annotate libpurple/dnsquery.c @ 31890:a86d2f291923

Simplify the PIN encryption code.
author andrew.victor@mxit.com
date Mon, 15 Aug 2011 20:10:35 +0000
parents 8dbe2f531a89
children d3d41ba0c3b8 3828a61c44da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file dnsquery.c DNS query API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
20074
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
6 /* purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 16634
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 */
31528
92f3d821653f purple: Fix some compiler warnings related to new API and missing prototypes.
Paul Aurich <paul@darkrain42.org>
parents: 31479
diff changeset
27 #define _PURPLE_DNSQUERY_C_
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "dnsquery.h"
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
32 #include "network.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include "notify.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "prefs.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36
26934
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
37 #ifndef _WIN32
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
38 #include <resolv.h>
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
39 #endif
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
40
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
41 #if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__)
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
42 #define PURPLE_DNSQUERY_USE_FORK
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
43 #endif
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 * DNS query API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
48 static PurpleDnsQueryUiOps *dns_query_ui_ops = NULL;
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
49
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
50 typedef struct _PurpleDnsQueryResolverProcess PurpleDnsQueryResolverProcess;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
52 struct _PurpleDnsQueryData {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 char *hostname;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 int port;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
55 PurpleDnsQueryConnectFunction callback;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 gpointer data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 guint timeout;
31479
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
58 PurpleAccount *account;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
60 #if defined(PURPLE_DNSQUERY_USE_FORK)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
61 PurpleDnsQueryResolverProcess *resolver;
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
62 #elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 GThread *resolver;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 GSList *hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 gchar *error_message;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
69 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 #define MAX_DNS_CHILDREN 4
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 * This structure keeps a reference to a child resolver process.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
76 struct _PurpleDnsQueryResolverProcess {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 guint inpa;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 int fd_in, fd_out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 pid_t dns_pid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 static GSList *free_dns_children = NULL;
27477
bbf5c43e269a Fix a leak of the queued_requests from purple_dnsquery_a.
aman@tmm1.net
parents: 27231
diff changeset
83 /* TODO: Make me a GQueue when we require >= glib 2.4 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 static GSList *queued_requests = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 static int number_of_dns_children = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 * This is a convenience struct used to pass data to
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 * the child resolver process.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 typedef struct {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 char hostname[512];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 int port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 } dns_params_t;
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
96 #endif /* end PURPLE_DNSQUERY_USE_FORK */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
99 purple_dnsquery_resolved(PurpleDnsQueryData *query_data, GSList *hosts)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
101 purple_debug_info("dnsquery", "IP resolved for %s\n", query_data->hostname);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 if (query_data->callback != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 query_data->callback(hosts, query_data->data, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 * Callback is a required parameter, but it can get set to
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 * NULL if we cancel a thread-based DNS lookup. So we need
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 * to free hosts.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 while (hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 hosts = g_slist_remove(hosts, hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 g_free(hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 hosts = g_slist_remove(hosts, hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
24126
cd35c0f680b9 Fix DNS resolution. I think I broke this this morning in my revision
Mark Doliner <mark@kingant.net>
parents: 24125
diff changeset
119 #ifdef PURPLE_DNSQUERY_USE_FORK
24121
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
120 /*
24126
cd35c0f680b9 Fix DNS resolution. I think I broke this this morning in my revision
Mark Doliner <mark@kingant.net>
parents: 24125
diff changeset
121 * Add the resolver to the list of available resolvers, and set it
cd35c0f680b9 Fix DNS resolution. I think I broke this this morning in my revision
Mark Doliner <mark@kingant.net>
parents: 24125
diff changeset
122 * to NULL so that it doesn't get destroyed along with the query_data
24121
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
123 */
27479
5345dfe48272 Don't assume a resolver generated the response.
aman@tmm1.net
parents: 27478
diff changeset
124 if (query_data->resolver)
5345dfe48272 Don't assume a resolver generated the response.
aman@tmm1.net
parents: 27478
diff changeset
125 {
5345dfe48272 Don't assume a resolver generated the response.
aman@tmm1.net
parents: 27478
diff changeset
126 free_dns_children = g_slist_prepend(free_dns_children, query_data->resolver);
5345dfe48272 Don't assume a resolver generated the response.
aman@tmm1.net
parents: 27478
diff changeset
127 query_data->resolver = NULL;
5345dfe48272 Don't assume a resolver generated the response.
aman@tmm1.net
parents: 27478
diff changeset
128 }
24126
cd35c0f680b9 Fix DNS resolution. I think I broke this this morning in my revision
Mark Doliner <mark@kingant.net>
parents: 24125
diff changeset
129 #endif /* PURPLE_DNSQUERY_USE_FORK */
24121
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
130
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
131 purple_dnsquery_destroy(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
135 purple_dnsquery_failed(PurpleDnsQueryData *query_data, const gchar *error_message)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 {
27231
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 26934
diff changeset
137 purple_debug_error("dnsquery", "%s\n", error_message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 if (query_data->callback != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 query_data->callback(NULL, query_data->data, error_message);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
140 purple_dnsquery_destroy(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
143 static gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
144 purple_dnsquery_ui_resolve(PurpleDnsQueryData *query_data)
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
145 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
146 PurpleDnsQueryUiOps *ops = purple_dnsquery_get_ui_ops();
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
147
15711
7ac07c5fb1c2 No changes; fixed a bunch of whitespace problems made by a text editor with 'use tabs' disabled. Sorry for the noise.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15709
diff changeset
148 if (ops && ops->resolve_host)
24124
dab570436008 Simplify two bits of code a little
Mark Doliner <mark@kingant.net>
parents: 24123
diff changeset
149 return ops->resolve_host(query_data, purple_dnsquery_resolved, purple_dnsquery_failed);
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
150
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
151 return FALSE;
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
152 }
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
153
27478
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
154 static gboolean
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
155 resolve_ip(PurpleDnsQueryData *query_data)
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
156 {
31746
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
157 #if defined(HAVE_GETADDRINFO) && defined(AI_NUMERICHOST)
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
158 struct addrinfo hints, *res;
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
159 char servname[20];
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
160
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
161 g_snprintf(servname, sizeof(servname), "%d", query_data->port);
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
162 memset(&hints, 0, sizeof(hints));
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
163 hints.ai_family = AF_UNSPEC;
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
164 hints.ai_flags |= AI_NUMERICHOST;
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
165
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
166 if (0 == getaddrinfo(query_data->hostname, servname, &hints, &res))
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
167 {
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
168 GSList *hosts = NULL;
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
169 hosts = g_slist_append(hosts, GINT_TO_POINTER(res->ai_addrlen));
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
170 hosts = g_slist_append(hosts, g_memdup(res->ai_addr, res->ai_addrlen));
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
171 purple_dnsquery_resolved(query_data, hosts);
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
172
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
173 freeaddrinfo(res);
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
174 return TRUE;
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
175 }
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
176 #else /* defined(HAVE_GETADDRINFO) && defined(AI_NUMERICHOST) */
27478
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
177 struct sockaddr_in sin;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
178 if (inet_aton(query_data->hostname, &sin.sin_addr))
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
179 {
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
180 /*
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
181 * The given "hostname" is actually an IP address, so we
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
182 * don't need to do anything.
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
183 */
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
184 GSList *hosts = NULL;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
185 sin.sin_family = AF_INET;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
186 sin.sin_port = htons(query_data->port);
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
187 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
188 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
189 purple_dnsquery_resolved(query_data, hosts);
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
190
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
191 return TRUE;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
192 }
31746
8dbe2f531a89 dnsquery: Behold, automagic conversion of a string IP address into a sockaddr struct, IPv#-independent.
Paul Aurich <paul@darkrain42.org>
parents: 31528
diff changeset
193 #endif
27478
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
194
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
195 return FALSE;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
196 }
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
197
28474
1c6c53143afe dns: Avoid two warnings when building with --disable-idn.
Paul Aurich <paul@darkrain42.org>
parents: 28301
diff changeset
198 #ifdef USE_IDN
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
199 static gboolean
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
200 dns_str_is_ascii(const char *name)
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
201 {
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
202 guchar *c;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
203 for (c = (guchar *)name; c && *c; ++c) {
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
204 if (*c > 0x7f)
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
205 return FALSE;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
206 }
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
207
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
208 return TRUE;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
209 }
28474
1c6c53143afe dns: Avoid two warnings when building with --disable-idn.
Paul Aurich <paul@darkrain42.org>
parents: 28301
diff changeset
210 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
211
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
212 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 * Unix!
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 * Begin the DNS resolver child process functions.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 #ifdef HAVE_SIGNAL_H
16634
c028fc690b5d Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents: 15828
diff changeset
222 G_GNUC_NORETURN static void
22011
76e0463db3aa Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@wiktel.com>
parents: 22007
diff changeset
223 trap_gdb_bug(int sig)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 const char *message =
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
226 "Purple's DNS child got a SIGTRAP signal.\n"
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
227 "This can be caused by trying to run purple inside gdb.\n"
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
228 "There is a known gdb bug which prevents this. Supposedly purple\n"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 "should have detected you were using gdb and used an ugly hack,\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 "check cope_with_gdb_brokenness() in dnsquery.c.\n\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 fputs("\n* * *\n",stderr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 fputs(message,stderr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 fputs("* * *\n\n",stderr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 execlp("xmessage","xmessage","-center", message, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 _exit(1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
240 static void
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
241 write_to_parent(int fd, const void *buf, size_t count)
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
242 {
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
243 ssize_t written;
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
244
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
245 written = write(fd, buf, count);
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
246 if (written != count) {
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
247 if (written < 0)
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
248 fprintf(stderr, "dns[%d]: Error writing data to "
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
249 "parent: %s\n", getpid(), strerror(errno));
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
250 else
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
251 fprintf(stderr, "dns[%d]: Error: Tried to write %"
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
252 G_GSIZE_FORMAT " bytes to parent but instead "
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
253 "wrote %" G_GSIZE_FORMAT " bytes\n",
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
254 getpid(), count, written);
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
255 }
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
256 }
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
257
16634
c028fc690b5d Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents: 15828
diff changeset
258 G_GNUC_NORETURN static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
259 purple_dnsquery_resolver_run(int child_out, int child_in, gboolean show_debug)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 dns_params_t dns_params;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 const size_t zero = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 int rc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 struct addrinfo hints, *res, *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 char servname[20];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 struct sockaddr_in sin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 const size_t addrlen = sizeof(sin);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
271 char *hostname;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 #ifdef HAVE_SIGNAL_H
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
274 purple_restore_default_signal_handlers();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 signal(SIGTRAP, trap_gdb_bug);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 * We resolve 1 host name for each iteration of this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 * while loop.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 * The top half of this reads in the hostname and port
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 * number from the socket with our parent. The bottom
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 * half of this resolves the IP (blocking) and sends
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 * the result back to our parent, when finished.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 while (1) {
24121
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
288 fd_set fds;
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
289 struct timeval tv = { .tv_sec = 20, .tv_usec = 0 };
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
290 FD_ZERO(&fds);
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
291 FD_SET(child_in, &fds);
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
292 rc = select(child_in + 1, &fds, NULL, NULL, &tv);
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
293 if (!rc) {
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
294 if (show_debug)
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
295 printf("dns[%d]: nobody needs me... =(\n", getpid());
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
296 break;
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
297 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 rc = read(child_in, &dns_params, sizeof(dns_params_t));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 if (rc < 0) {
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
300 fprintf(stderr, "dns[%d]: Error: Could not read dns_params: "
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
301 "%s\n", getpid(), strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 if (rc == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 if (show_debug)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid());
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 _exit(0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 if (dns_params.hostname[0] == '\0') {
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
310 fprintf(stderr, "dns[%d]: Error: Parent requested resolution "
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
311 "of an empty hostname (port = %d)!!!\n", getpid(),
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
312 dns_params.port);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 _exit(1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
316 #ifdef USE_IDN
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
317 if (!dns_str_is_ascii(dns_params.hostname)) {
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
318 rc = purple_network_convert_idn_to_ascii(dns_params.hostname, &hostname);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
319 if (rc != 0) {
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
320 write_to_parent(child_out, &rc, sizeof(rc));
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
321 if (show_debug)
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
322 fprintf(stderr, "dns[%d] Error: IDN conversion returned "
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
323 "%d\n", getpid(), rc);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
324 dns_params.hostname[0] = '\0';
28475
4370819b97ff dns: I don't think this worked correctly before.
Paul Aurich <paul@darkrain42.org>
parents: 28474
diff changeset
325 break;
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
326 }
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
327 } else /* intentional to execute the g_strdup */
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
328 #endif
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
329 hostname = g_strdup(dns_params.hostname);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
330
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 /* We have the hostname and port, now resolve the IP */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 g_snprintf(servname, sizeof(servname), "%d", dns_params.port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 memset(&hints, 0, sizeof(hints));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 /* This is only used to convert a service
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 * name to a port number. As we know we are
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 * passing a number already, we know this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 * value will not be really used by the C
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 * library.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 hints.ai_socktype = SOCK_STREAM;
26923
cf373257effb Don't do IPv6 AAAA lookups if there is no IPv6 address configured on
Mark Doliner <mark@kingant.net>
parents: 26885
diff changeset
344 #ifdef AI_ADDRCONFIG
cf373257effb Don't do IPv6 AAAA lookups if there is no IPv6 address configured on
Mark Doliner <mark@kingant.net>
parents: 26885
diff changeset
345 hints.ai_flags |= AI_ADDRCONFIG;
cf373257effb Don't do IPv6 AAAA lookups if there is no IPv6 address configured on
Mark Doliner <mark@kingant.net>
parents: 26885
diff changeset
346 #endif /* AI_ADDRCONFIG */
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
347 rc = getaddrinfo(hostname, servname, &hints, &res);
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
348 write_to_parent(child_out, &rc, sizeof(rc));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 if (rc != 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 if (show_debug)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 printf("dns[%d] Error: getaddrinfo returned %d\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 getpid(), rc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 dns_params.hostname[0] = '\0';
28299
4c58aa4aacb0 Minor leak fixes. Probably not too important since they're in DNS resolver
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 28294
diff changeset
354 g_free(hostname);
4c58aa4aacb0 Minor leak fixes. Probably not too important since they're in DNS resolver
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 28294
diff changeset
355 hostname = NULL;
28475
4370819b97ff dns: I don't think this worked correctly before.
Paul Aurich <paul@darkrain42.org>
parents: 28474
diff changeset
356 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 tmp = res;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 while (res) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 size_t ai_addrlen = res->ai_addrlen;
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
361 write_to_parent(child_out, &ai_addrlen, sizeof(ai_addrlen));
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
362 write_to_parent(child_out, res->ai_addr, res->ai_addrlen);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 res = res->ai_next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 freeaddrinfo(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 #else
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
367 struct hostent *hp;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
368 if (!(hp = gethostbyname(hostname))) {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
369 write_to_parent(child_out, &h_errno, sizeof(int));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
370 close(child_out);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
371 if (show_debug)
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
372 printf("DNS Error: %d\n", h_errno);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
373 _exit(0);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
374 }
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
375 memset(&sin, 0, sizeof(struct sockaddr_in));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
376 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
377 sin.sin_family = hp->h_addrtype;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 sin.sin_port = htons(dns_params.port);
24916
1596d09393cf Ludovico Cavedon noticed that on 64-bit platforms, when HAVE_GETADDRINFO isn't
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24469
diff changeset
380 rc = 0;
1596d09393cf Ludovico Cavedon noticed that on 64-bit platforms, when HAVE_GETADDRINFO isn't
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24469
diff changeset
381 write_to_parent(child_out, &rc, sizeof(rc));
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
382 write_to_parent(child_out, &addrlen, sizeof(addrlen));
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
383 write_to_parent(child_out, &sin, addrlen);
24916
1596d09393cf Ludovico Cavedon noticed that on 64-bit platforms, when HAVE_GETADDRINFO isn't
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24469
diff changeset
384 #endif
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
385 write_to_parent(child_out, &zero, sizeof(zero));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 dns_params.hostname[0] = '\0';
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
387
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
388 g_free(hostname);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
389 hostname = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 close(child_out);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 close(child_in);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 _exit(0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 * End the DNS resolver child process functions.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 * Begin the functions for dealing with the DNS child processes.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 static void
22007
c38d72677c8a Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents: 21862
diff changeset
405 cope_with_gdb_brokenness(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 #ifdef __linux__
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 static gboolean already_done = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 char s[256], e[512];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 int n;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 pid_t ppid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 if(already_done)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 already_done = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 ppid = getppid();
26885
8290e36a5a73 A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
Richard Laager <rlaager@wiktel.com>
parents: 24916
diff changeset
417 g_snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 n = readlink(s, e, sizeof(e));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 if(n < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 e[MIN(n,sizeof(e)-1)] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 if(strstr(e,"gdb")) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
425 purple_debug_info("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 "Debugger detected, performing useless query...\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 gethostbyname("x.x.x.x.x");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
433 purple_dnsquery_resolver_destroy(PurpleDnsQueryResolverProcess *resolver)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 g_return_if_fail(resolver != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436
24469
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
437 /* Keep this before the kill() call below. */
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
438 if (resolver->inpa != 0) {
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
439 purple_input_remove(resolver->inpa);
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
440 resolver->inpa = 0;
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
441 }
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
442
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 * We might as well attempt to kill our child process. It really
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 * doesn't matter if this fails, because children will expire on
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 * their own after a few seconds.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 if (resolver->dns_pid > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 kill(resolver->dns_pid, SIGKILL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 close(resolver->fd_in);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 close(resolver->fd_out);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 g_free(resolver);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 number_of_dns_children--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
459 static PurpleDnsQueryResolverProcess *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
460 purple_dnsquery_resolver_new(gboolean show_debug)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
462 PurpleDnsQueryResolverProcess *resolver;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 int child_out[2], child_in[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 /* Create pipes for communicating with the child process */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 if (pipe(child_out) || pipe(child_in)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
467 purple_debug_error("dns",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20320
diff changeset
468 "Could not create pipes: %s\n", g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
472 resolver = g_new(PurpleDnsQueryResolverProcess, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 resolver->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 cope_with_gdb_brokenness();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 /* "Go fork and multiply." --Tommy Caldwell (Emily's dad, not the climber) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 resolver->dns_pid = fork();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 /* If we are the child process... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 if (resolver->dns_pid == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 /* We should not access the parent's side of the pipes, so close them */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 close(child_out[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 close(child_in[1]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
486 purple_dnsquery_resolver_run(child_out[1], child_in[0], show_debug);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 /* The thread calls _exit() rather than returning, so we never get here */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 /* We should not access the child's side of the pipes, so close them */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 close(child_out[1]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 close(child_in[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 if (resolver->dns_pid == -1) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
494 purple_debug_error("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 "Could not create child process for DNS: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20320
diff changeset
496 g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
497 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 resolver->fd_out = child_out[0];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 resolver->fd_in = child_in[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 number_of_dns_children++;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
504 purple_debug_info("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 "Created new DNS child %d, there are now %d children.\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 resolver->dns_pid, number_of_dns_children);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 return resolver;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 * @return TRUE if the request was sent succesfully. FALSE
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
513 * if the request could not be sent. This isn't
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
514 * necessarily an error. If the child has expired,
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
515 * for example, we won't be able to send the message.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517 static gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
518 send_dns_request_to_child(PurpleDnsQueryData *query_data,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
519 PurpleDnsQueryResolverProcess *resolver)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 pid_t pid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 dns_params_t dns_params;
24081
b703102fa0a5 Fix this g_return_val_if_fail. It should have been returning TRUE or
Mark Doliner <mark@kingant.net>
parents: 24080
diff changeset
523 ssize_t rc;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 /* This waitpid might return the child's PID if it has recently
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 * exited, or it might return an error if it exited "long
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 * enough" ago that it has already been reaped; in either
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 * instance, we can't use it. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 pid = waitpid(resolver->dns_pid, NULL, WNOHANG);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 if (pid > 0) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
531 purple_debug_warning("dns", "DNS child %d no longer exists\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 resolver->dns_pid);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
533 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 } else if (pid < 0) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
536 purple_debug_warning("dns", "Wait for DNS child %d failed: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20320
diff changeset
537 resolver->dns_pid, g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
538 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 /* Copy the hostname and port into a single data structure */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 strncpy(dns_params.hostname, query_data->hostname, sizeof(dns_params.hostname) - 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 dns_params.port = query_data->port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 /* Send the data structure to the child */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 rc = write(resolver->fd_in, &dns_params, sizeof(dns_params));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 if (rc < 0) {
22486
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22107
diff changeset
550 purple_debug_error("dns", "Unable to write to DNS child %d: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20320
diff changeset
551 resolver->dns_pid, g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
552 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 }
24081
b703102fa0a5 Fix this g_return_val_if_fail. It should have been returning TRUE or
Mark Doliner <mark@kingant.net>
parents: 24080
diff changeset
555 if (rc < sizeof(dns_params)) {
24183
6c8f5ebbb6b7 Fix this debug message. Thanks to fledermaus who pointed it out.
Mark Doliner <mark@kingant.net>
parents: 24126
diff changeset
556 purple_debug_error("dns", "Tried to write %" G_GSSIZE_FORMAT
6c8f5ebbb6b7 Fix this debug message. Thanks to fledermaus who pointed it out.
Mark Doliner <mark@kingant.net>
parents: 24126
diff changeset
557 " bytes to child but only wrote %" G_GSSIZE_FORMAT "\n",
24081
b703102fa0a5 Fix this g_return_val_if_fail. It should have been returning TRUE or
Mark Doliner <mark@kingant.net>
parents: 24080
diff changeset
558 sizeof(dns_params), rc);
b703102fa0a5 Fix this g_return_val_if_fail. It should have been returning TRUE or
Mark Doliner <mark@kingant.net>
parents: 24080
diff changeset
559 purple_dnsquery_resolver_destroy(resolver);
b703102fa0a5 Fix this g_return_val_if_fail. It should have been returning TRUE or
Mark Doliner <mark@kingant.net>
parents: 24080
diff changeset
560 return FALSE;
b703102fa0a5 Fix this g_return_val_if_fail. It should have been returning TRUE or
Mark Doliner <mark@kingant.net>
parents: 24080
diff changeset
561 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
563 purple_debug_info("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 "Successfully sent DNS request to child %d\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 resolver->dns_pid);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 query_data->resolver = resolver;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
572 static void host_resolved(gpointer data, gint source, PurpleInputCondition cond);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 static void
22007
c38d72677c8a Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents: 21862
diff changeset
575 handle_next_queued_request(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
577 PurpleDnsQueryData *query_data;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
578 PurpleDnsQueryResolverProcess *resolver;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 if (queued_requests == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 /* No more DNS queries, yay! */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 query_data = queued_requests->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 queued_requests = g_slist_delete_link(queued_requests, queued_requests);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 * If we have any children, attempt to have them perform the DNS
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 * query. If we're able to send the query then resolver will be
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
590 * set to the PurpleDnsQueryResolverProcess. Otherwise, resolver
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 * will be NULL and we'll need to create a new DNS request child.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 while (free_dns_children != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 resolver = free_dns_children->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596 free_dns_children = g_slist_remove(free_dns_children, resolver);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 if (send_dns_request_to_child(query_data, resolver))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 /* We found an acceptable child, yay */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 /* We need to create a new DNS request child */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 if (query_data->resolver == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 if (number_of_dns_children >= MAX_DNS_CHILDREN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 /* Apparently all our children are busy */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 queued_requests = g_slist_prepend(queued_requests, query_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
613 resolver = purple_dnsquery_resolver_new(purple_debug_is_enabled());
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 if (resolver == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
616 purple_dnsquery_failed(query_data, _("Unable to create new resolver process\n"));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 if (!send_dns_request_to_child(query_data, resolver))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
621 purple_dnsquery_failed(query_data, _("Unable to send request to resolver process\n"));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
626 query_data->resolver->inpa = purple_input_add(query_data->resolver->fd_out,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
627 PURPLE_INPUT_READ, host_resolved, query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 * End the functions for dealing with the DNS child processes.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
635 host_resolved(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
637 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 int rc, err;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 GSList *hosts = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 struct sockaddr *addr = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 size_t addrlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 char message[1024];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 query_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
646 purple_debug_info("dns", "Got response for '%s'\n", query_data->hostname);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
647 purple_input_remove(query_data->resolver->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 query_data->resolver->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 rc = read(query_data->resolver->fd_out, &err, sizeof(err));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 if ((rc == 4) && (err != 0))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 g_snprintf(message, sizeof(message), _("Error resolving %s:\n%s"),
21862
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21121
diff changeset
655 query_data->hostname, purple_gai_strerror(err));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 query_data->hostname, err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 #endif
26934
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
660 /* Re-read resolv.conf and friends in case DNS servers have changed */
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
661 res_init();
c162a088489f Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents: 26923
diff changeset
662
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
663 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 } else if (rc > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665 /* Success! */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 while (rc > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 rc = read(query_data->resolver->fd_out, &addrlen, sizeof(addrlen));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 if (rc > 0 && addrlen > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 addr = g_malloc(addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 rc = read(query_data->resolver->fd_out, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 hosts = g_slist_append(hosts, addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677 /* wait4(resolver->dns_pid, NULL, WNOHANG, NULL); */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
678 purple_dnsquery_resolved(query_data, hosts);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680 } else if (rc == -1) {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20320
diff changeset
681 g_snprintf(message, sizeof(message), _("Error reading from resolver process:\n%s"), g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
682 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 } else if (rc == 0) {
24123
14c5a8bbaa8d Change a string to be more user friendly (people shouldn't have any idea
Mark Doliner <mark@kingant.net>
parents: 24122
diff changeset
685 g_snprintf(message, sizeof(message), _("Resolver process exited without answering our request"));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
686 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
689 handle_next_queued_request();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
692 static void
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
693 resolve_host(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694 {
27477
bbf5c43e269a Fix a leak of the queued_requests from purple_dnsquery_a.
aman@tmm1.net
parents: 27231
diff changeset
695 queued_requests = g_slist_append(queued_requests, query_data);
bbf5c43e269a Fix a leak of the queued_requests from purple_dnsquery_a.
aman@tmm1.net
parents: 27231
diff changeset
696
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 handle_next_queued_request();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
700 #elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 * Windows!
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
704 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
706 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
707 dns_main_thread_cb(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708 {
20320
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
709 PurpleDnsQueryData *query_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710
20320
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
711 /* We're done, so purple_dnsquery_destroy() shouldn't think it is canceling an in-progress lookup */
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
712 query_data->resolver = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714 if (query_data->error_message != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
715 purple_dnsquery_failed(query_data, query_data->error_message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
718 GSList *hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
720 /* We don't want purple_dns_query_resolved() to free(hosts) */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
721 hosts = query_data->hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722 query_data->hosts = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
723 purple_dnsquery_resolved(query_data, hosts);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
725
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
726 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
727 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
728
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
729 static gpointer
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
730 dns_thread(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
731 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
732 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
733 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
734 int rc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
735 struct addrinfo hints, *res, *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
736 char servname[20];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
737 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
738 struct sockaddr_in sin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
739 struct hostent *hp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
740 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
741 char *hostname;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
742
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
743 query_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
744
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
745 #ifdef USE_IDN
27638
8b669aaa3ed7 Build fix on Windows. Thanks to SuperMMX.
Paul Aurich <paul@darkrain42.org>
parents: 27635
diff changeset
746 if (!dns_str_is_ascii(query_data->hostname)) {
8b669aaa3ed7 Build fix on Windows. Thanks to SuperMMX.
Paul Aurich <paul@darkrain42.org>
parents: 27635
diff changeset
747 rc = purple_network_convert_idn_to_ascii(query_data->hostname, &hostname);
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
748 if (rc != 0) {
28300
160b864e3d9b Fix a string now that we're not in string freeze. Thanks, QuLogic!
Paul Aurich <paul@darkrain42.org>
parents: 28294
diff changeset
749 query_data->error_message = g_strdup_printf(_("Error converting %s "
160b864e3d9b Fix a string now that we're not in string freeze. Thanks, QuLogic!
Paul Aurich <paul@darkrain42.org>
parents: 28294
diff changeset
750 "to punycode: %d"), query_data->hostname, rc);
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
751 /* back to main thread */
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
752 purple_timeout_add(0, dns_main_thread_cb, query_data);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
753 return 0;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
754 }
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
755 } else /* intentional fallthru */
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
756 #endif
27638
8b669aaa3ed7 Build fix on Windows. Thanks to SuperMMX.
Paul Aurich <paul@darkrain42.org>
parents: 27635
diff changeset
757 hostname = g_strdup(query_data->hostname);
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
758
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 g_snprintf(servname, sizeof(servname), "%d", query_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761 memset(&hints,0,sizeof(hints));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
762
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
763 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764 * This is only used to convert a service
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 * name to a port number. As we know we are
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
766 * passing a number already, we know this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
767 * value will not be really used by the C
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
768 * library.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770 hints.ai_socktype = SOCK_STREAM;
26923
cf373257effb Don't do IPv6 AAAA lookups if there is no IPv6 address configured on
Mark Doliner <mark@kingant.net>
parents: 26885
diff changeset
771 #ifdef AI_ADDRCONFIG
cf373257effb Don't do IPv6 AAAA lookups if there is no IPv6 address configured on
Mark Doliner <mark@kingant.net>
parents: 26885
diff changeset
772 hints.ai_flags |= AI_ADDRCONFIG;
cf373257effb Don't do IPv6 AAAA lookups if there is no IPv6 address configured on
Mark Doliner <mark@kingant.net>
parents: 26885
diff changeset
773 #endif /* AI_ADDRCONFIG */
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
774 if ((rc = getaddrinfo(hostname, servname, &hints, &res)) == 0) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
775 tmp = res;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
776 while(res) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
777 query_data->hosts = g_slist_append(query_data->hosts,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
778 GSIZE_TO_POINTER(res->ai_addrlen));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
779 query_data->hosts = g_slist_append(query_data->hosts,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
780 g_memdup(res->ai_addr, res->ai_addrlen));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781 res = res->ai_next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
782 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
783 freeaddrinfo(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
784 } else {
21862
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21121
diff changeset
785 query_data->error_message = g_strdup_printf(_("Error resolving %s:\n%s"), query_data->hostname, purple_gai_strerror(rc));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
786 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787 #else
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
788 if ((hp = gethostbyname(hostname))) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
789 memset(&sin, 0, sizeof(struct sockaddr_in));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
790 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
791 sin.sin_family = hp->h_addrtype;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 sin.sin_port = htons(query_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
794 query_data->hosts = g_slist_append(query_data->hosts,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
795 GSIZE_TO_POINTER(sizeof(sin)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
796 query_data->hosts = g_slist_append(query_data->hosts,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
797 g_memdup(&sin, sizeof(sin)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
798 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799 query_data->error_message = g_strdup_printf(_("Error resolving %s: %d"), query_data->hostname, h_errno);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
801 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
802 g_free(hostname);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
803
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
804 /* back to main thread */
20320
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
805 purple_timeout_add(0, dns_main_thread_cb, query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
807 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
808 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
809
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
810 static void
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
811 resolve_host(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
813 GError *err = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
815 /*
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
816 * Spin off a separate thread to perform the DNS lookup so
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
817 * that we don't block the UI.
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
818 */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
819 query_data->resolver = g_thread_create(dns_thread,
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
820 query_data, FALSE, &err);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
821 if (query_data->resolver == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822 {
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
823 char message[1024];
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
824 g_snprintf(message, sizeof(message), _("Thread creation failure: %s"),
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
825 (err && err->message) ? err->message : _("Unknown reason"));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
826 g_error_free(err);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
827 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
828 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
829 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
830
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
831 #else /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
832
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
833 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
834 * We weren't able to do anything fancier above, so use the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 * fail-safe name resolution code, which is blocking.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
836 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
838 static void
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
839 resolve_host(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
840 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
841 struct sockaddr_in sin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
842 GSList *hosts = NULL;
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
843 struct hostent *hp;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
844 gchar *hostname;
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
845 #ifdef USE_IDN
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
846 if (!dns_str_is_ascii(query_data->hostname)) {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
847 int ret = purple_network_convert_idn_to_ascii(query_data->hostname,
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
848 &hostname);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
849 if (ret != 0) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
850 char message[1024];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
851 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
852 query_data->hostname, ret);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
853 purple_dnsquery_failed(query_data, message);
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
854 return;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
855 }
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
856 } else /* fallthrough is intentional to the g_strdup */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
857 #endif
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
858 hostname = g_strdup(query_data->hostname);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
859
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
860 if(!(hp = gethostbyname(hostname))) {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
861 char message[1024];
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
862 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
863 query_data->hostname, h_errno);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
864 purple_dnsquery_failed(query_data, message);
28294
578b4048a501 More tightly scope a variable and avoid trying to free an unset variable.
brian.lu@sun.com
parents: 27638
diff changeset
865 g_free(hostname);
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
866 return;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
867 }
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
868 memset(&sin, 0, sizeof(struct sockaddr_in));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
869 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
870 sin.sin_family = hp->h_addrtype;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
871 g_free(hostname);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
872 sin.sin_port = htons(query_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
873
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
874 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
875 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
876
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
877 purple_dnsquery_resolved(query_data, hosts);
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
878 }
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
879
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
880 #endif /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
881
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
882 static gboolean
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
883 initiate_resolving(gpointer data)
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
884 {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
885 PurpleDnsQueryData *query_data;
31479
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
886 PurpleProxyType proxy_type;
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
887
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
888 query_data = data;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
889 query_data->timeout = 0;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
890
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
891 if (resolve_ip(query_data))
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
892 /* resolve_ip calls purple_dnsquery_resolved */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
893 return FALSE;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
894
31479
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
895 proxy_type = purple_proxy_info_get_type(
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
896 purple_proxy_get_setup(query_data->account));
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
897 if (proxy_type == PURPLE_PROXY_TOR) {
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
898 purple_dnsquery_failed(query_data,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
899 _("Aborting DNS lookup in Tor Proxy mode."));
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
900 return FALSE;
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
901 }
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
902
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
903 if (purple_dnsquery_ui_resolve(query_data))
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
904 /* The UI is handling the resolve; we're done */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
905 return FALSE;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
906
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
907 resolve_host(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
908
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
910 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
912 PurpleDnsQueryData *
31479
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
913 purple_dnsquery_a_account(PurpleAccount *account, const char *hostname, int port,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
914 PurpleDnsQueryConnectFunction callback, gpointer data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
915 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
916 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 g_return_val_if_fail(hostname != NULL, NULL);
31474
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
919 g_return_val_if_fail(port != 0, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 g_return_val_if_fail(callback != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
921
31474
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
922 purple_debug_info("dnsquery", "Performing DNS lookup for %s\n", hostname);
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
923
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
924 query_data = g_new0(PurpleDnsQueryData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
925 query_data->hostname = g_strdup(hostname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
926 g_strstrip(query_data->hostname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
927 query_data->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
928 query_data->callback = callback;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929 query_data->data = data;
31479
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
930 query_data->account = account;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
931
31474
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
932 if (*query_data->hostname == '\0')
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
933 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
934 purple_dnsquery_destroy(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
935 g_return_val_if_reached(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
936 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
938 query_data->timeout = purple_timeout_add(0, initiate_resolving, query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940 return query_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942
31479
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
943 PurpleDnsQueryData *
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
944 purple_dnsquery_a(const char *hostname, int port,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
945 PurpleDnsQueryConnectFunction callback, gpointer data)
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
946 {
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
947 return purple_dnsquery_a_account(NULL, hostname, port, callback, data);
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31475
diff changeset
948 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
949
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
951 purple_dnsquery_destroy(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
952 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
953 PurpleDnsQueryUiOps *ops = purple_dnsquery_get_ui_ops();
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
954
15711
7ac07c5fb1c2 No changes; fixed a bunch of whitespace problems made by a text editor with 'use tabs' disabled. Sorry for the noise.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15709
diff changeset
955 if (ops && ops->destroy)
7ac07c5fb1c2 No changes; fixed a bunch of whitespace problems made by a text editor with 'use tabs' disabled. Sorry for the noise.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15709
diff changeset
956 ops->destroy(query_data);
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
957
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
958 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 queued_requests = g_slist_remove(queued_requests, query_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
960
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961 if (query_data->resolver != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
962 /*
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
963 * This is only non-NULL when we're cancelling an in-progress
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
964 * query. Ideally we would tell our resolver child to stop
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
965 * resolving shit and then we would add it back to the
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
966 * free_dns_children linked list. However, it's hard to tell
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
967 * children stuff, they just don't listen. So we'll just
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
968 * kill the process and allow a new child to be started if we
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
969 * have more stuff to resolve.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
970 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
971 purple_dnsquery_resolver_destroy(query_data->resolver);
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
972 #elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
973 if (query_data->resolver != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
974 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
975 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
976 * It's not really possible to kill a thread. So instead we
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977 * just set the callback to NULL and let the DNS lookup
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
978 * finish.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
979 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 query_data->callback = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
983
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
984 while (query_data->hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
986 /* Discard the length... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
987 query_data->hosts = g_slist_remove(query_data->hosts, query_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
988 /* Free the address... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
989 g_free(query_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
990 query_data->hosts = g_slist_remove(query_data->hosts, query_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
991 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
992 g_free(query_data->error_message);
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
993 #endif /* end _WIN32 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
994
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
995 if (query_data->timeout > 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
996 purple_timeout_remove(query_data->timeout);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
997
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
998 g_free(query_data->hostname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
999 g_free(query_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1000 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1001
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1002 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1003 purple_dnsquery_get_host(PurpleDnsQueryData *query_data)
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1004 {
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1005 g_return_val_if_fail(query_data != NULL, NULL);
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1006
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1007 return query_data->hostname;
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1008 }
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1009
15709
d253c87a6a1f Remove a g_return_val_if_fail() which isn't needed, made gaim_dnsquery_get_port() return an unsigned short and return 0 if query_data is NULL, and fixed a whitespace mistake
Evan Schoenberg <evan.s@dreskin.net>
parents: 15705
diff changeset
1010 unsigned short
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1011 purple_dnsquery_get_port(PurpleDnsQueryData *query_data)
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1012 {
15709
d253c87a6a1f Remove a g_return_val_if_fail() which isn't needed, made gaim_dnsquery_get_port() return an unsigned short and return 0 if query_data is NULL, and fixed a whitespace mistake
Evan Schoenberg <evan.s@dreskin.net>
parents: 15705
diff changeset
1013 g_return_val_if_fail(query_data != NULL, 0);
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1014
15711
7ac07c5fb1c2 No changes; fixed a bunch of whitespace problems made by a text editor with 'use tabs' disabled. Sorry for the noise.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15709
diff changeset
1015 return query_data->port;
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1016 }
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1017
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1018 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1019 purple_dnsquery_set_ui_ops(PurpleDnsQueryUiOps *ops)
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1020 {
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1021 dns_query_ui_ops = ops;
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1022 }
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1023
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1024 PurpleDnsQueryUiOps *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1025 purple_dnsquery_get_ui_ops(void)
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1026 {
15709
d253c87a6a1f Remove a g_return_val_if_fail() which isn't needed, made gaim_dnsquery_get_port() return an unsigned short and return 0 if query_data is NULL, and fixed a whitespace mistake
Evan Schoenberg <evan.s@dreskin.net>
parents: 15705
diff changeset
1027 /* It is perfectly acceptable for dns_query_ui_ops to be NULL; this just
d253c87a6a1f Remove a g_return_val_if_fail() which isn't needed, made gaim_dnsquery_get_port() return an unsigned short and return 0 if query_data is NULL, and fixed a whitespace mistake
Evan Schoenberg <evan.s@dreskin.net>
parents: 15705
diff changeset
1028 * means that the default platform-specific implementation will be used.
d253c87a6a1f Remove a g_return_val_if_fail() which isn't needed, made gaim_dnsquery_get_port() return an unsigned short and return 0 if query_data is NULL, and fixed a whitespace mistake
Evan Schoenberg <evan.s@dreskin.net>
parents: 15705
diff changeset
1029 */
15704
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1030 return dns_query_ui_ops;
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1031 }
6a0b9734a722 The UI can now use the GaimDnsQueryUiOps to handle DNS resolving itself; if this is done, the platform-specific DNS query code won't be used. This will be used in Adium to use an efficient threads-based DNS resolve (since Adium is already multithreaded, this is significantly cheaper than fork()).
Evan Schoenberg <evan.s@dreskin.net>
parents: 15645
diff changeset
1032
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1033 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1034 purple_dnsquery_init(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1035 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1036 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1037
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1038 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1039 purple_dnsquery_uninit(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1040 {
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22486
diff changeset
1041 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1042 while (free_dns_children != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1043 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1044 purple_dnsquery_resolver_destroy(free_dns_children->data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1045 free_dns_children = g_slist_remove(free_dns_children, free_dns_children->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1046 }
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
1047 #endif /* end PURPLE_DNSQUERY_USE_FORK */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048 }