annotate libpurple/dnsquery.c @ 31729:8e1b248adc55

We have not been in 2009 while ago nor this project is dead.
author masca@cpw.pidgin.im
date Fri, 08 Jul 2011 01:37:00 +0000
parents 92f3d821653f
children 8dbe2f531a89
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 {
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
157 struct sockaddr_in sin;
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
158 /* TODO: Use inet_pton for IPv6 support */
27478
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
159 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
160 {
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
161 /*
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
162 * 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
163 * don't need to do anything.
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
164 */
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
165 GSList *hosts = NULL;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
166 sin.sin_family = AF_INET;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
167 sin.sin_port = htons(query_data->port);
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
168 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
169 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
170 purple_dnsquery_resolved(query_data, hosts);
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
171
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
172 return TRUE;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
173 }
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
174
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
175 return FALSE;
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
176 }
75ef7eab4978 Don't fork a resolver process for IPs.
aman@tmm1.net
parents: 27477
diff changeset
177
28474
1c6c53143afe dns: Avoid two warnings when building with --disable-idn.
Paul Aurich <paul@darkrain42.org>
parents: 28301
diff changeset
178 #ifdef USE_IDN
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
179 static gboolean
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
180 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
181 {
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
182 guchar *c;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
183 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
184 if (*c > 0x7f)
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
185 return FALSE;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
186 }
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
187
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
188 return TRUE;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
189 }
28474
1c6c53143afe dns: Avoid two warnings when building with --disable-idn.
Paul Aurich <paul@darkrain42.org>
parents: 28301
diff changeset
190 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
191
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
192 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 * Unix!
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 * Begin the DNS resolver child process functions.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 #ifdef HAVE_SIGNAL_H
16634
c028fc690b5d Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents: 15828
diff changeset
202 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
203 trap_gdb_bug(int sig)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 const char *message =
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
206 "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
207 "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
208 "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
209 "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
210 "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
211 "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
212 fputs("\n* * *\n",stderr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 fputs(message,stderr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 fputs("* * *\n\n",stderr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 execlp("xmessage","xmessage","-center", message, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 _exit(1);
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 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
220 static void
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
221 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
222 {
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
223 ssize_t written;
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
224
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
225 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
226 if (written != count) {
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
227 if (written < 0)
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
228 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
229 "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
230 else
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
231 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
232 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
233 "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
234 getpid(), count, written);
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
235 }
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
236 }
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
237
16634
c028fc690b5d Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents: 15828
diff changeset
238 G_GNUC_NORETURN static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
239 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
240 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 dns_params_t dns_params;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 const size_t zero = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 int rc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 struct addrinfo hints, *res, *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 char servname[20];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 struct sockaddr_in sin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 const size_t addrlen = sizeof(sin);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
251 char *hostname;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 #ifdef HAVE_SIGNAL_H
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
254 purple_restore_default_signal_handlers();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 signal(SIGTRAP, trap_gdb_bug);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 * 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
260 * while loop.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 * 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
263 * 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
264 * 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
265 * 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
266 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 while (1) {
24121
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
268 fd_set fds;
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
269 struct timeval tv = { .tv_sec = 20, .tv_usec = 0 };
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
270 FD_ZERO(&fds);
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
271 FD_SET(child_in, &fds);
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
272 rc = select(child_in + 1, &fds, NULL, NULL, &tv);
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
273 if (!rc) {
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
274 if (show_debug)
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
275 printf("dns[%d]: nobody needs me... =(\n", getpid());
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
276 break;
5395b18f9f08 Revert my revision 849d4f7265598a9f0340411c4c0c0401d488ec3b, which
Mark Doliner <mark@kingant.net>
parents: 24081
diff changeset
277 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 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
279 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
280 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
281 "%s\n", getpid(), strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 if (rc == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 if (show_debug)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 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
287 _exit(0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 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
290 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
291 "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
292 dns_params.port);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 _exit(1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
296 #ifdef USE_IDN
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
297 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
298 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
299 if (rc != 0) {
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
300 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
301 if (show_debug)
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
302 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
303 "%d\n", getpid(), rc);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
304 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
305 break;
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
306 }
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
307 } 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
308 #endif
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
309 hostname = g_strdup(dns_params.hostname);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
310
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 /* 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
312
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 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
315 memset(&hints, 0, sizeof(hints));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 /* 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
318 * 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
319 * passing a number already, we know this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 * 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
321 * library.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 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
324 #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
325 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
326 #endif /* AI_ADDRCONFIG */
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
327 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
328 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
329 if (rc != 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 if (show_debug)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 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
332 getpid(), rc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 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
334 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
335 hostname = NULL;
28475
4370819b97ff dns: I don't think this worked correctly before.
Paul Aurich <paul@darkrain42.org>
parents: 28474
diff changeset
336 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 tmp = res;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 while (res) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 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
341 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
342 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
343 res = res->ai_next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 freeaddrinfo(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 #else
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
347 struct hostent *hp;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
348 if (!(hp = gethostbyname(hostname))) {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
349 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
350 close(child_out);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
351 if (show_debug)
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
352 printf("DNS Error: %d\n", h_errno);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
353 _exit(0);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
354 }
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
355 memset(&sin, 0, sizeof(struct sockaddr_in));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
356 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
357 sin.sin_family = hp->h_addrtype;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 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
360 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
361 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
362 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
363 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
364 #endif
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 22011
diff changeset
365 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
366 dns_params.hostname[0] = '\0';
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
367
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
368 g_free(hostname);
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
369 hostname = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 close(child_out);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 close(child_in);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 _exit(0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 * End the DNS resolver child process functions.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 * 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
383 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 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
385 cope_with_gdb_brokenness(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 #ifdef __linux__
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 static gboolean already_done = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 char s[256], e[512];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 int n;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 pid_t ppid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 if(already_done)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 already_done = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 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
397 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
398 n = readlink(s, e, sizeof(e));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 if(n < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 return;
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 e[MIN(n,sizeof(e)-1)] = '\0';
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 if(strstr(e,"gdb")) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
405 purple_debug_info("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 "Debugger detected, performing useless query...\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 gethostbyname("x.x.x.x.x");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
413 purple_dnsquery_resolver_destroy(PurpleDnsQueryResolverProcess *resolver)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 g_return_if_fail(resolver != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416
24469
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
417 /* 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
418 if (resolver->inpa != 0) {
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
419 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
420 resolver->inpa = 0;
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
421 }
002a58d4af7d Fix a crash Jacky Lam noted on devel@pidgin.im:
Richard Laager <rlaager@wiktel.com>
parents: 24183
diff changeset
422
15373
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 * 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
425 * 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
426 * their own after a few seconds.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 if (resolver->dns_pid > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 kill(resolver->dns_pid, SIGKILL);
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 close(resolver->fd_in);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 close(resolver->fd_out);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 g_free(resolver);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 number_of_dns_children--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
439 static PurpleDnsQueryResolverProcess *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
440 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
441 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
442 PurpleDnsQueryResolverProcess *resolver;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 int child_out[2], child_in[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 /* 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
446 if (pipe(child_out) || pipe(child_in)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
447 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
448 "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
449 return NULL;
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
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
452 resolver = g_new(PurpleDnsQueryResolverProcess, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 resolver->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 cope_with_gdb_brokenness();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 /* "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
458 resolver->dns_pid = fork();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 /* If we are the child process... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 if (resolver->dns_pid == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 /* 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
463 close(child_out[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 close(child_in[1]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
466 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
467 /* 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
468 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 /* 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
471 close(child_out[1]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 close(child_in[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 if (resolver->dns_pid == -1) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
474 purple_debug_error("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 "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
476 g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
477 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 return NULL;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 resolver->fd_out = child_out[0];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 resolver->fd_in = child_in[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 number_of_dns_children++;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
484 purple_debug_info("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 "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
486 resolver->dns_pid, number_of_dns_children);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 return resolver;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 * @return TRUE if the request was sent succesfully. FALSE
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
493 * if the request could not be sent. This isn't
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
494 * necessarily an error. If the child has expired,
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
495 * 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
496 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 static gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
498 send_dns_request_to_child(PurpleDnsQueryData *query_data,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
499 PurpleDnsQueryResolverProcess *resolver)
15373
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 pid_t pid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 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
503 ssize_t rc;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 /* 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
506 * 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
507 * 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
508 * instance, we can't use it. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 pid = waitpid(resolver->dns_pid, NULL, WNOHANG);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 if (pid > 0) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
511 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
512 resolver->dns_pid);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
513 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 } else if (pid < 0) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
516 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
517 resolver->dns_pid, g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
518 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 return FALSE;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 /* 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
523 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
524 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
525 dns_params.port = query_data->port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 /* Send the data structure to the child */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 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
529 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
530 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
531 resolver->dns_pid, g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
532 purple_dnsquery_resolver_destroy(resolver);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 }
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
535 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
536 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
537 " 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
538 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
539 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
540 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
541 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
543 purple_debug_info("dns",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 "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
545 resolver->dns_pid);
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 query_data->resolver = resolver;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
552 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
553
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 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
555 handle_next_queued_request(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
557 PurpleDnsQueryData *query_data;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
558 PurpleDnsQueryResolverProcess *resolver;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 if (queued_requests == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 /* No more DNS queries, yay! */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 query_data = queued_requests->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 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
566
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568 * 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
569 * 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
570 * set to the PurpleDnsQueryResolverProcess. Otherwise, resolver
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 * 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
572 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 while (free_dns_children != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 resolver = free_dns_children->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 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
577
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 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
579 /* We found an acceptable child, yay */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 /* 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
584 if (query_data->resolver == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 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
587 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 /* Apparently all our children are busy */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 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
590 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
593 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
594 if (resolver == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
596 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
597 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 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
600 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
601 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
602 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
606 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
607 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
608 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 * 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
612 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
615 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
616 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
617 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 int rc, err;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 GSList *hosts = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 struct sockaddr *addr = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 size_t addrlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 char message[1024];
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 query_data = data;
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 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
627 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
628 query_data->resolver->inpa = 0;
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 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
631 if ((rc == 4) && (err != 0))
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 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 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
635 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
636 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 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
638 query_data->hostname, err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 #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
640 /* 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
641 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
642
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
643 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 } else if (rc > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645 /* Success! */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 while (rc > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 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
648 if (rc > 0 && addrlen > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649 addr = g_malloc(addrlen);
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, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 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
652 hosts = g_slist_append(hosts, addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 /* wait4(resolver->dns_pid, NULL, WNOHANG, NULL); */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
658 purple_dnsquery_resolved(query_data, hosts);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 } 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
661 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
662 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 } 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
665 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
666 purple_dnsquery_failed(query_data, message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 handle_next_queued_request();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
672 static void
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
673 resolve_host(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674 {
27477
bbf5c43e269a Fix a leak of the queued_requests from purple_dnsquery_a.
aman@tmm1.net
parents: 27231
diff changeset
675 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
676
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677 handle_next_queued_request();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679
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
680 #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
681
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
682 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 * Windows!
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 dns_main_thread_cb(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688 {
20320
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
689 PurpleDnsQueryData *query_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690
20320
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
691 /* 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
692 query_data->resolver = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694 if (query_data->error_message != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
695 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
696 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698 GSList *hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
700 /* 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
701 hosts = query_data->hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702 query_data->hosts = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
703 purple_dnsquery_resolved(query_data, hosts);
15373
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 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
707 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
709 static gpointer
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710 dns_thread(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
711 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
712 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714 int rc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715 struct addrinfo hints, *res, *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 char servname[20];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
718 struct sockaddr_in sin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719 struct hostent *hp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
720 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
721 char *hostname;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
723 query_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
725 #ifdef USE_IDN
27638
8b669aaa3ed7 Build fix on Windows. Thanks to SuperMMX.
Paul Aurich <paul@darkrain42.org>
parents: 27635
diff changeset
726 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
727 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
728 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
729 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
730 "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
731 /* back to main thread */
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
732 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
733 return 0;
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
734 }
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
735 } else /* intentional fallthru */
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
736 #endif
27638
8b669aaa3ed7 Build fix on Windows. Thanks to SuperMMX.
Paul Aurich <paul@darkrain42.org>
parents: 27635
diff changeset
737 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
738
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
739 #ifdef HAVE_GETADDRINFO
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
740 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
741 memset(&hints,0,sizeof(hints));
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 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
744 * 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
745 * 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
746 * passing a number already, we know this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747 * 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
748 * library.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
749 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
750 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
751 #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
752 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
753 #endif /* AI_ADDRCONFIG */
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
754 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
755 tmp = res;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
756 while(res) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
757 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
758 GSIZE_TO_POINTER(res->ai_addrlen));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759 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
760 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
761 res = res->ai_next;
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 freeaddrinfo(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764 } else {
21862
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21121
diff changeset
765 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
766 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
767 #else
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
768 if ((hp = gethostbyname(hostname))) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 memset(&sin, 0, sizeof(struct sockaddr_in));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770 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
771 sin.sin_family = hp->h_addrtype;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
772 sin.sin_port = htons(query_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
774 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
775 GSIZE_TO_POINTER(sizeof(sin)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
776 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
777 g_memdup(&sin, sizeof(sin)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
778 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
779 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
780 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781 #endif
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
782 g_free(hostname);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
783
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
784 /* back to main thread */
20320
6a128c9bd170 applied changes from 77376fe079e753b612b3b8c901060e689f3dee11
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
785 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
786
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
788 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
789
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
790 static void
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
791 resolve_host(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793 GError *err = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
794
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
795 /*
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
796 * 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
797 * that we don't block the UI.
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
798 */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
799 query_data->resolver = g_thread_create(dns_thread,
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
800 query_data, FALSE, &err);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
801 if (query_data->resolver == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
802 {
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
803 char message[1024];
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
804 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
805 (err && err->message) ? err->message : _("Unknown reason"));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
806 g_error_free(err);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
807 purple_dnsquery_failed(query_data, message);
15373
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
810
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
811 #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
812
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
813 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814 * 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
815 * 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
816 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
817
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
818 static void
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
819 resolve_host(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
820 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
821 struct sockaddr_in sin;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822 GSList *hosts = NULL;
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
823 struct hostent *hp;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
824 gchar *hostname;
27635
7fbf964c6c6c Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents: 27479
diff changeset
825 #ifdef USE_IDN
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
826 if (!dns_str_is_ascii(query_data->hostname)) {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
827 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
828 &hostname);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
829 if (ret != 0) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
830 char message[1024];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
831 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
832 query_data->hostname, ret);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
833 purple_dnsquery_failed(query_data, message);
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
834 return;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 }
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
836 } else /* fallthrough is intentional to the g_strdup */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
837 #endif
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
838 hostname = g_strdup(query_data->hostname);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
839
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
840 if(!(hp = gethostbyname(hostname))) {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
841 char message[1024];
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
842 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
843 query_data->hostname, h_errno);
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
844 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
845 g_free(hostname);
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
846 return;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
847 }
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
848 memset(&sin, 0, sizeof(struct sockaddr_in));
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
849 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
850 sin.sin_family = hp->h_addrtype;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
851 g_free(hostname);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
852 sin.sin_port = htons(query_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
853
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
854 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
855 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
856
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
857 purple_dnsquery_resolved(query_data, hosts);
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
858 }
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 #endif /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
861
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
862 static gboolean
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
863 initiate_resolving(gpointer data)
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
864 {
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
865 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
866 PurpleProxyType proxy_type;
31475
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 query_data = data;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
869 query_data->timeout = 0;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
870
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
871 if (resolve_ip(query_data))
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
872 /* resolve_ip calls purple_dnsquery_resolved */
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
873 return FALSE;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
874
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
875 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
876 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
877 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
878 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
879 _("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
880 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
881 }
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
882
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
883 if (purple_dnsquery_ui_resolve(query_data))
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
884 /* 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
885 return FALSE;
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
886
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
887 resolve_host(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
888
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
892 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
893 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
894 PurpleDnsQueryConnectFunction callback, gpointer data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
895 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
896 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
897
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898 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
899 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
900 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
901
31474
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
902 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
903
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
904 query_data = g_new0(PurpleDnsQueryData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
905 query_data->hostname = g_strdup(hostname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
906 g_strstrip(query_data->hostname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
907 query_data->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
908 query_data->callback = callback;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909 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
910 query_data->account = account;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911
31474
74e2492967be Consolidate duplicated implementations of purple_dnsquery_a
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28475
diff changeset
912 if (*query_data->hostname == '\0')
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
913 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
914 purple_dnsquery_destroy(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
915 g_return_val_if_reached(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917
31475
68a1efda3654 Further consolidation of dnsquery code.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31474
diff changeset
918 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
919
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 return query_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
921 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
922
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
923 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
924 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
925 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
926 {
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
927 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
928 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
930 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
931 purple_dnsquery_destroy(PurpleDnsQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
932 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
933 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
934
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
935 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
936 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
937
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
938 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939 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
940
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941 if (query_data->resolver != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 /*
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
943 * 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
944 * query. Ideally we would tell our resolver child to stop
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
945 * 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
946 * 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
947 * 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
948 * 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
949 * have more stuff to resolve.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
951 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
952 #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
953 if (query_data->resolver != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
956 * 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
957 * 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
958 * finish.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
960 query_data->callback = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
962 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
963
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
964 while (query_data->hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
965 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
966 /* Discard the length... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
967 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
968 /* Free the address... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
969 g_free(query_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
970 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
971 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
972 g_free(query_data->error_message);
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
973 #endif /* end _WIN32 */
15373
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 if (query_data->timeout > 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
976 purple_timeout_remove(query_data->timeout);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
978 g_free(query_data->hostname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
979 g_free(query_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981
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
982 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
983 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
984 {
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
985 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
986
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
987 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
988 }
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
989
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
990 unsigned short
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
991 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
992 {
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
993 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
994
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
995 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
996 }
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
997
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
998 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
999 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
1000 {
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
1001 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
1002 }
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
1003
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1004 PurpleDnsQueryUiOps *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1005 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
1006 {
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
1007 /* 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
1008 * 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
1009 */
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
1010 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
1011 }
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
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1013 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1014 purple_dnsquery_init(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1015 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1016 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1017
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1018 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1019 purple_dnsquery_uninit(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1020 {
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
1021 #if defined(PURPLE_DNSQUERY_USE_FORK)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1022 while (free_dns_children != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1023 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15711
diff changeset
1024 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
1025 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
1026 }
24122
6dae9cefd3a1 Improve a few comments
Mark Doliner <mark@kingant.net>
parents: 24121
diff changeset
1027 #endif /* end PURPLE_DNSQUERY_USE_FORK */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1028 }