libpurple/dnssrv.c

Sun, 01 Nov 2009 03:23:03 +0000

author
Paul Aurich <darkrain42@pidgin.im>
date
Sun, 01 Nov 2009 03:23:03 +0000
changeset 28792
77214d07508f
parent 28784
0344b94dba21
child 29253
4621bf356c67
child 29638
13c95d82cb5f
child 29647
3d4a2db1dc6b
permissions
-rw-r--r--

dns: Check read/write return value to silence a bunch of warnings.

11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1 /**
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
2 * @file dnssrv.c
20330
650a7af9c238 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
3 */
650a7af9c238 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
4
650a7af9c238 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
5 /* purple
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
6 *
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
7 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
8 *
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
12 * (at your option) any later version.
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
13 *
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
17 * GNU General Public License for more details.
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
18 *
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18555
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
22 */
11898
a40601f1aed2 [gaim-migrate @ 14189]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11630
diff changeset
23
a40601f1aed2 [gaim-migrate @ 14189]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11630
diff changeset
24 #include "internal.h"
15718
216ce4a9db5b Include util.h to fix a warning I introduced
Evan Schoenberg <evands@pidgin.im>
parents: 15707
diff changeset
25 #include "util.h"
11898
a40601f1aed2 [gaim-migrate @ 14189]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11630
diff changeset
26
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
27 #ifndef _WIN32
23352
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22351
diff changeset
28 #include <arpa/nameser.h>
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
29 #include <resolv.h>
12568
717c7d5cbb77 [gaim-migrate @ 14887]
Richard Laager <rlaager@pidgin.im>
parents: 12451
diff changeset
30 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
31 #include <arpa/nameser_compat.h>
12568
717c7d5cbb77 [gaim-migrate @ 14887]
Richard Laager <rlaager@pidgin.im>
parents: 12451
diff changeset
32 #endif
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
33 #ifndef T_SRV
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
34 #define T_SRV 33
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
35 #endif
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
36 #ifndef T_TXT
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
37 #define T_TXT 16
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
38 #endif
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
39 #else /* WIN32 */
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
40 #include <windns.h>
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
41 /* Missing from the mingw headers */
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
42 #ifndef DNS_TYPE_SRV
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
43 # define DNS_TYPE_SRV 33
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
44 #endif
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
45 #ifndef DNS_TYPE_TXT
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
46 # define DNS_TYPE_TXT 16
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
47 #endif
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
48 #endif
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
49
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
50 #include "debug.h"
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
51 #include "dnssrv.h"
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
52 #include "eventloop.h"
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
53 #include "network.h"
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
54
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
55 #ifndef _WIN32
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
56 typedef union {
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
57 HEADER hdr;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
58 u_char buf[1024];
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
59 } queryans;
11395
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
60 #else
18555
ececd1bd99e3 Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents: 16957
diff changeset
61 static DNS_STATUS (WINAPI *MyDnsQuery_UTF8) (
11395
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
62 PCSTR lpstrName, WORD wType, DWORD fOptions,
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
63 PIP4_ARRAY aipServers, PDNS_RECORD* ppQueryResultsSet,
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
64 PVOID* pReserved) = NULL;
18555
ececd1bd99e3 Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents: 16957
diff changeset
65 static void (WINAPI *MyDnsRecordListFree) (PDNS_RECORD pRecordList,
11395
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
66 DNS_FREE_TYPE FreeType) = NULL;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
67 #endif
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
68
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
69 struct _PurpleTxtResponse {
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
70 char *content;
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
71 };
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
72
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
73 struct _PurpleSrvQueryData {
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
74 union {
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
75 PurpleSrvCallback srv;
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
76 PurpleTxtCallback txt;
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
77 } cb;
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
78
11382
4458ab177b10 [gaim-migrate @ 13609]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11381
diff changeset
79 gpointer extradata;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
80 guint handle;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
81 int type;
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
82 #ifdef _WIN32
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
83 GThread *resolver;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
84 char *query;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
85 char *error_message;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
86 GList *results;
15776
cba54f9d2e51 Patch from Graham Booker which ensures that a process forked by dnsserv cleans up afterwards, calling waitpid() to make sure no zombies are left over.
Evan Schoenberg <evands@pidgin.im>
parents: 15718
diff changeset
87 #else
20128
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
88 int fd_in, fd_out;
15776
cba54f9d2e51 Patch from Graham Booker which ensures that a process forked by dnsserv cleans up afterwards, calling waitpid() to make sure no zombies are left over.
Evan Schoenberg <evands@pidgin.im>
parents: 15718
diff changeset
89 pid_t pid;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
90 #endif
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
91 };
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
92
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
93 typedef struct _PurpleSrvInternalQuery {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
94 int type;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
95 char query[256];
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
96 } PurpleSrvInternalQuery;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
97
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
98 typedef struct _PurpleSrvResponseContainer {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
99 PurpleSrvResponse *response;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
100 int sum;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
101 } PurpleSrvResponseContainer;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
102
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
103 /**
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
104 * Sort by priority, then by weight. Strictly numerically--no
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
105 * randomness. Technically we only need to sort by pref and then
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
106 * make sure any records with weight 0 are at the beginning of
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
107 * their group, but it's just as easy to sort by weight.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
108 */
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
109 static gint
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
110 responsecompare(gconstpointer ar, gconstpointer br)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
111 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
112 PurpleSrvResponse *a = (PurpleSrvResponse*)ar;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
113 PurpleSrvResponse *b = (PurpleSrvResponse*)br;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
114
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
115 if(a->pref == b->pref) {
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
116 if(a->weight == b->weight)
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
117 return 0;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
118 if(a->weight < b->weight)
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
119 return -1;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
120 return 1;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
121 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
122 if(a->pref < b->pref)
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
123 return -1;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
124 return 1;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
125 }
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
126
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
127 /**
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
128 * Iterate over a list of PurpleSrvResponseContainer making the sum
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
129 * the running total of the sums. Select a random integer in the range
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
130 * (1, sum+1), then find the first element greater than or equal to the
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
131 * number selected. From RFC 2782.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
132 *
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
133 * @param list The list of PurpleSrvResponseContainer. This function
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
134 * removes a node from this list and returns the new list.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
135 * @param container_ptr The PurpleSrvResponseContainer that was chosen
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
136 * will be returned here.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
137 */
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
138 static GList *
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
139 select_random_response(GList *list, PurpleSrvResponseContainer **container_ptr)
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
140 {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
141 GList *cur;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
142 size_t runningtotal;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
143 int r;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
144
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
145 runningtotal = 0;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
146 cur = list;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
147
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
148 while (cur) {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
149 PurpleSrvResponseContainer *container = cur->data;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
150 runningtotal += container->response->weight;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
151 container->sum = runningtotal;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
152 cur = cur->next;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
153 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
154
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
155 /*
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
156 * If the running total is greater than 0, pick a number between
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
157 * 1 and the runningtotal inclusive. (This is not precisely what
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
158 * the RFC algorithm describes, but we wish to deal with integers
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
159 * and avoid floats. This is functionally equivalent.)
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
160 * If running total is 0, then choose r = 0.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
161 */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
162 r = runningtotal ? g_random_int_range(1, runningtotal + 1) : 0;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
163 cur = list;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
164 while (r > ((PurpleSrvResponseContainer *)cur->data)->sum) {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
165 cur = cur->next;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
166 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
167
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
168 /* Set the return parameter and remove cur from the list */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
169 *container_ptr = cur->data;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
170 return g_list_delete_link(list, cur);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
171 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
172
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
173 /**
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
174 * Reorder a GList of PurpleSrvResponses that have the same priority
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
175 * (aka "pref").
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
176 */
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
177 static void
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
178 srv_reorder(GList *list, int num)
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
179 {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
180 int i;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
181 GList *cur, *container_list = NULL;
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
182 PurpleSrvResponseContainer *container;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
183
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
184 if (num < 2)
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
185 /* Nothing to sort */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
186 return;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
187
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
188 /* First build a list of container structs */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
189 for (i = 0, cur = list; i < num; i++, cur = cur->next) {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
190 container = g_new(PurpleSrvResponseContainer, 1);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
191 container->response = cur->data;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
192 container_list = g_list_prepend(container_list, container);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
193 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
194 container_list = g_list_reverse(container_list);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
195
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
196 /*
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
197 * Re-order the list that was passed in as a parameter. We leave
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
198 * the list nodes in place, but replace their data pointers.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
199 */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
200 cur = list;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
201 while (container_list) {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
202 container_list = select_random_response(container_list, &container);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
203 cur->data = container->response;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
204 g_free(container);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
205 cur = cur->next;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
206 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
207 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
208
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
209 /**
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
210 * Sorts a GList of PurpleSrvResponses according to the
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
211 * algorithm described in RFC 2782.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
212 *
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
213 * @param response GList of PurpleSrvResponse's
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
214 * @param The original list, resorted
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
215 */
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
216 static GList *
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
217 purple_srv_sort(GList *list)
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
218 {
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
219 int pref, count;
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
220 GList *cur, *start;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
221
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
222 if (!list || !list->next) {
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
223 /* Nothing to sort */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
224 return list;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
225 }
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
226
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
227 list = g_list_sort(list, responsecompare);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
228
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
229 start = cur = list;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
230 count = 1;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
231 while (cur) {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
232 PurpleSrvResponse *next_response;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
233 pref = ((PurpleSrvResponse *)cur->data)->pref;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
234 next_response = cur->next ? cur->next->data : NULL;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
235 if (!next_response || next_response->pref != pref) {
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
236 /*
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
237 * The 'count' records starting at 'start' all have the same
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
238 * priority. Sort them by weight.
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
239 */
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
240 srv_reorder(start, count);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
241 start = cur->next;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
242 count = 0;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
243 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
244 count++;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
245 cur = cur->next;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
246 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
247
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
248 return list;
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
249 }
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
250
28784
0344b94dba21 dns: Avoid two warnings when building with --disable-idn.
Paul Aurich <darkrain42@pidgin.im>
parents: 28675
diff changeset
251 #ifdef USE_IDN
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
252 static gboolean
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
253 dns_str_is_ascii(const char *name)
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
254 {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
255 guchar *c;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
256 for (c = (guchar *)name; c && *c; ++c) {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
257 if (*c > 0x7f)
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
258 return FALSE;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
259 }
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
260
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
261 return TRUE;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
262 }
28784
0344b94dba21 dns: Avoid two warnings when building with --disable-idn.
Paul Aurich <darkrain42@pidgin.im>
parents: 28675
diff changeset
263 #endif
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
264
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
265 #ifndef _WIN32
28792
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
266 static void
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
267 write_to_parent(int in, int out, gconstpointer data, gsize size)
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
268 {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
269 const guchar *buf = data;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
270 gssize w;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
271
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
272 do {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
273 w = write(out, buf, size);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
274 if (w > 0) {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
275 buf += w;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
276 size -= w;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
277 } else if (w < 0 && errno == EINTR) {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
278 /* Let's try some more; */
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
279 w = 1;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
280 }
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
281 } while (size > 0 && w > 0);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
282
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
283 if (size != 0) {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
284 /* An error occurred */
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
285 close(out);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
286 close(in);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
287 _exit(0);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
288 }
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
289 }
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
290
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
291 /* Read size bytes to data. Dies if an error occurs. */
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
292 static void
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
293 read_from_parent(int in, int out, gpointer data, gsize size)
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
294 {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
295 guchar *buf = data;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
296 gssize r;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
297
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
298 do {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
299 r = read(in, data, size);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
300 if (r > 0) {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
301 buf += r;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
302 size -= r;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
303 } else if (r < 0 && errno == EINTR) {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
304 /* Let's try some more; */
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
305 r = 1;
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
306 }
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
307 } while (size > 0 && r > 0);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
308
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
309 if (size != 0) {
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
310 /* An error occurred */
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
311 close(out);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
312 close(in);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
313 _exit(0);
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
314 }
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
315 }
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
316
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
317
16701
0b41f23396cc Mark two functions as "noreturn"
Mark Doliner <markdoliner@pidgin.im>
parents: 15890
diff changeset
318 G_GNUC_NORETURN static void
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
319 resolve(int in, int out)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
320 {
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
321 GList *ret = NULL;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
322 PurpleSrvResponse *srvres;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
323 PurpleTxtResponse *txtres;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
324 queryans answer;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
325 int size, qdcount, ancount;
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
326 guchar *end, *cp;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
327 gchar name[256];
13127
0adfbecc67ac [gaim-migrate @ 15488]
Mark Doliner <markdoliner@pidgin.im>
parents: 12847
diff changeset
328 guint16 type, dlen, pref, weight, port;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
329 PurpleSrvInternalQuery query;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
330
15707
e9d3280caf69 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
331 #ifdef HAVE_SIGNAL_H
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
332 purple_restore_default_signal_handlers();
15707
e9d3280caf69 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
333 #endif
15859
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
334
28792
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
335 read_from_parent(in, out, &query, sizeof(query));
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
336
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
337 size = res_query( query.query, C_IN, query.type, (u_char*)&answer, sizeof( answer));
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
338 if (size == -1) {
28792
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
339 write_to_parent(in, out, &(query.type), sizeof(query.type));
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
340 write_to_parent(in, out, &size, sizeof(size));
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
341 close(out);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
342 close(in);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
343 _exit(0);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
344 }
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
345
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
346 qdcount = ntohs(answer.hdr.qdcount);
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
347 ancount = ntohs(answer.hdr.ancount);
11381
d3d53604fe0f [gaim-migrate @ 13608]
Mark Doliner <markdoliner@pidgin.im>
parents: 11379
diff changeset
348 cp = (guchar*)&answer + sizeof(HEADER);
d3d53604fe0f [gaim-migrate @ 13608]
Mark Doliner <markdoliner@pidgin.im>
parents: 11379
diff changeset
349 end = (guchar*)&answer + size;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
350
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
351 /* skip over unwanted stuff */
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
352 while (qdcount-- > 0 && cp < end) {
11381
d3d53604fe0f [gaim-migrate @ 13608]
Mark Doliner <markdoliner@pidgin.im>
parents: 11379
diff changeset
353 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
354 if(size < 0) goto end;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
355 cp += size + QFIXEDSZ;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
356 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
357
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
358 while (ancount-- > 0 && cp < end) {
11381
d3d53604fe0f [gaim-migrate @ 13608]
Mark Doliner <markdoliner@pidgin.im>
parents: 11379
diff changeset
359 size = dn_expand((unsigned char*)&answer, end, cp, name, 256);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
360 if(size < 0)
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
361 goto end;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
362 cp += size;
13143
d0a29ff182c8 [gaim-migrate @ 15505]
Mark Doliner <markdoliner@pidgin.im>
parents: 13127
diff changeset
363 GETSHORT(type,cp);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
364
13127
0adfbecc67ac [gaim-migrate @ 15488]
Mark Doliner <markdoliner@pidgin.im>
parents: 12847
diff changeset
365 /* skip ttl and class since we already know it */
0adfbecc67ac [gaim-migrate @ 15488]
Mark Doliner <markdoliner@pidgin.im>
parents: 12847
diff changeset
366 cp += 6;
0adfbecc67ac [gaim-migrate @ 15488]
Mark Doliner <markdoliner@pidgin.im>
parents: 12847
diff changeset
367
13143
d0a29ff182c8 [gaim-migrate @ 15505]
Mark Doliner <markdoliner@pidgin.im>
parents: 13127
diff changeset
368 GETSHORT(dlen,cp);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
369 if (query.type == T_SRV) {
13143
d0a29ff182c8 [gaim-migrate @ 15505]
Mark Doliner <markdoliner@pidgin.im>
parents: 13127
diff changeset
370 GETSHORT(pref,cp);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
371
13143
d0a29ff182c8 [gaim-migrate @ 15505]
Mark Doliner <markdoliner@pidgin.im>
parents: 13127
diff changeset
372 GETSHORT(weight,cp);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
373
13143
d0a29ff182c8 [gaim-migrate @ 15505]
Mark Doliner <markdoliner@pidgin.im>
parents: 13127
diff changeset
374 GETSHORT(port,cp);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
375
11381
d3d53604fe0f [gaim-migrate @ 13608]
Mark Doliner <markdoliner@pidgin.im>
parents: 11379
diff changeset
376 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
377 if(size < 0 )
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
378 goto end;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
379
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
380 cp += size;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
381
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
382 srvres = g_new0(PurpleSrvResponse, 1);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
383 strcpy(srvres->hostname, name);
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
384 srvres->pref = pref;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
385 srvres->port = port;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
386 srvres->weight = weight;
11395
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
387
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
388 ret = g_list_prepend(ret, srvres);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
389 } else if (query.type == T_TXT) {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
390 txtres = g_new0(PurpleTxtResponse, 1);
26765
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
391 txtres->content = g_strndup((gchar*)(++cp), dlen-1);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
392 ret = g_list_append(ret, txtres);
23606
5e648a57bb76 * some further bugfixing, BIND's libresolv does so much for the programmer, just happy it exists
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23605
diff changeset
393 cp += dlen - 1;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
394 } else {
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
395 cp += dlen;
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
396 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
397 }
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
398
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
399 end:
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
400 size = g_list_length(ret);
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
401
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
402 if (query.type == T_SRV)
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
403 ret = purple_srv_sort(ret);
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
404
28792
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
405 write_to_parent(in, out, &(query.type), sizeof(query.type));
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
406 write_to_parent(in, out, &size, sizeof(size));
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
407 while (ret != NULL)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
408 {
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
409 if (query.type == T_SRV)
28792
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
410 write_to_parent(in, out, ret->data, sizeof(PurpleSrvResponse));
28674
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
411 if (query.type == T_TXT) {
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
412 PurpleTxtResponse *response = ret->data;
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
413 gsize l = strlen(response->content) + 1 /* null byte */;
28792
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
414 write_to_parent(in, out, &l, sizeof(l));
77214d07508f dns: Check read/write return value to silence a bunch of warnings.
Paul Aurich <darkrain42@pidgin.im>
parents: 28784
diff changeset
415 write_to_parent(in, out, response->content, l);
28674
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
416 }
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
417
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
418 g_free(ret->data);
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
419 ret = g_list_remove(ret, ret->data);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
420 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
421
20128
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
422 close(out);
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
423 close(in);
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
424
11395
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
425 _exit(0);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
426 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
427
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
428 static void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
429 resolved(gpointer data, gint source, PurpleInputCondition cond)
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
430 {
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
431 int size;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
432 int type;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
433 PurpleSrvQueryData *query_data = (PurpleSrvQueryData*)data;
11426
46f761f5c7ad [gaim-migrate @ 13663]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11395
diff changeset
434 int i;
15776
cba54f9d2e51 Patch from Graham Booker which ensures that a process forked by dnsserv cleans up afterwards, calling waitpid() to make sure no zombies are left over.
Evan Schoenberg <evands@pidgin.im>
parents: 15718
diff changeset
435 int status;
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
436
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
437 if (read(source, &type, sizeof(type)) == sizeof(type)) {
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
438 if (read(source, &size, sizeof(size)) == sizeof(size)) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
439 if (size == -1 || size == 0) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
440 if (size == -1) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
441 purple_debug_warning("dnssrv", "res_query returned an error\n");
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
442 /* Re-read resolv.conf and friends in case DNS servers have changed */
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
443 res_init();
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
444 } else
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
445 purple_debug_info("dnssrv", "Found 0 entries, errno is %i\n", errno);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
446
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
447 if (type == T_SRV) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
448 PurpleSrvCallback cb = query_data->cb.srv;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
449 cb(NULL, 0, query_data->extradata);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
450 } else if (type == T_TXT) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
451 PurpleTxtCallback cb = query_data->cb.txt;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
452 cb(NULL, query_data->extradata);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
453 } else {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
454 purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
455 }
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
456
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
457 } else if (size) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
458 if (type == T_SRV) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
459 PurpleSrvResponse *res;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
460 PurpleSrvResponse *tmp;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
461 PurpleSrvCallback cb = query_data->cb.srv;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
462 ssize_t red;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
463 purple_debug_info("dnssrv","found %d SRV entries\n", size);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
464 tmp = res = g_new0(PurpleSrvResponse, size);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
465 for (i = 0; i < size; i++) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
466 red = read(source, tmp++, sizeof(PurpleSrvResponse));
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
467 if (red != sizeof(PurpleSrvResponse)) {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
468 purple_debug_error("dnssrv","unable to read srv "
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
469 "response: %s\n", g_strerror(errno));
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
470 size = 0;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
471 g_free(res);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
472 res = NULL;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
473 }
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
474 }
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
475
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
476 cb(res, size, query_data->extradata);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
477 } else if (type == T_TXT) {
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
478 GList *responses = NULL;
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
479 PurpleTxtResponse *res;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
480 PurpleTxtCallback cb = query_data->cb.txt;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
481 ssize_t red;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
482 purple_debug_info("dnssrv","found %d TXT entries\n", size);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
483 for (i = 0; i < size; i++) {
28674
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
484 gsize len;
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
485
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
486 red = read(source, &len, sizeof(len));
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
487 if (red != sizeof(len)) {
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
488 purple_debug_error("dnssrv","unable to read txt "
28674
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
489 "response length: %s\n", g_strerror(errno));
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
490 size = 0;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
491 g_list_foreach(responses, (GFunc)purple_txt_response_destroy, NULL);
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
492 g_list_free(responses);
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
493 responses = NULL;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
494 break;
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
495 }
28674
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
496
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
497 res = g_new0(PurpleTxtResponse, 1);
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
498 res->content = g_new0(gchar, len);
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
499
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
500 red = read(source, res->content, len);
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
501 if (red != len) {
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
502 purple_debug_error("dnssrv","unable to read txt "
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
503 "response: %s\n", g_strerror(errno));
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
504 size = 0;
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
505 purple_txt_response_destroy(res);
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
506 g_list_foreach(responses, (GFunc)purple_txt_response_destroy, NULL);
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
507 g_list_free(responses);
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
508 responses = NULL;
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
509 break;
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
510 }
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
511 responses = g_list_prepend(responses, res);
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
512 }
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
513
28674
43442ff173dc Fix the code dealing with writing a TXT lookup response from child to parent.
Paul Aurich <darkrain42@pidgin.im>
parents: 28612
diff changeset
514 responses = g_list_reverse(responses);
27157
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
515 cb(responses, query_data->extradata);
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
516 } else {
609f187d0ac7 Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <darkrain42@pidgin.im>
parents: 26970
diff changeset
517 purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
518 }
22234
4d54e1c5c696 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <markdoliner@pidgin.im>
parents: 20679
diff changeset
519 }
16957
b74ce411bea8 If the read() in resolved() fails, we should detect the failure and set size (which it would otherwise set, since it is passed by reference) to 0 and res to NULL. This ''may'' fix a rather odd crash described in Adium Trac #6623 (http://trac.adiumx.com/ticket/6623), and it is certainly good sanity checking.
Evan Schoenberg <evands@pidgin.im>
parents: 16701
diff changeset
520 }
b74ce411bea8 If the read() in resolved() fails, we should detect the failure and set size (which it would otherwise set, since it is passed by reference) to 0 and res to NULL. This ''may'' fix a rather odd crash described in Adium Trac #6623 (http://trac.adiumx.com/ticket/6623), and it is certainly good sanity checking.
Evan Schoenberg <evands@pidgin.im>
parents: 16701
diff changeset
521 }
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
522
15776
cba54f9d2e51 Patch from Graham Booker which ensures that a process forked by dnsserv cleans up afterwards, calling waitpid() to make sure no zombies are left over.
Evan Schoenberg <evands@pidgin.im>
parents: 15718
diff changeset
523 waitpid(query_data->pid, &status, 0);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
524 purple_srv_cancel(query_data);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
525 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
526
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
527 #else /* _WIN32 */
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
528
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
529 /** The Jabber Server code was inspiration for parts of this. */
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
530
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
531 static gboolean
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
532 res_main_thread_cb(gpointer data)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
533 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
534 PurpleSrvResponse *srvres = NULL;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
535 PurpleSrvQueryData *query_data = data;
28291
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
536 if(query_data->error_message != NULL) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
537 purple_debug_error("dnssrv", query_data->error_message);
28291
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
538 if (query_data->type == DNS_TYPE_SRV) {
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
539 if (query_data->cb.srv)
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
540 query_data->cb.srv(srvres, 0, query_data->extradata);
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
541 } else if (query_data->type == DNS_TYPE_TXT) {
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
542 if (query_data->cb.txt)
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
543 query_data->cb.txt(NULL, query_data->extradata);
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
544 }
a342ad3611b0 Fix not calling the SRV timeout on the win32 code. Closes #9956.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
545 } else {
26968
0527c5cc906b Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <darkrain42@pidgin.im>
parents: 26766
diff changeset
546 if (query_data->type == DNS_TYPE_SRV) {
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
547 PurpleSrvResponse *srvres_tmp = NULL;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
548 GList *lst = query_data->results;
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
549 int size = g_list_length(lst);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
550
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
551 if(query_data->cb.srv && size > 0)
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
552 srvres_tmp = srvres = g_new0(PurpleSrvResponse, size);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
553 while (lst) {
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
554 PurpleSrvResponse *lstdata = lst->data;
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
555 lst = g_list_delete_link(lst, lst);
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
556
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
557 if(query_data->cb.srv)
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
558 memcpy(srvres_tmp++, lstdata, sizeof(PurpleSrvResponse));
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
559 g_free(lstdata);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
560 }
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
561
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
562 query_data->results = NULL;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
563
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
564 purple_debug_info("dnssrv", "found %d SRV entries\n", size);
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
565
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
566 if(query_data->cb.srv) query_data->cb.srv(srvres, size, query_data->extradata);
26968
0527c5cc906b Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <darkrain42@pidgin.im>
parents: 26766
diff changeset
567 } else if (query_data->type == DNS_TYPE_TXT) {
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
568 GList *lst = query_data->results;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
569
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
570 purple_debug_info("dnssrv", "found %d TXT entries\n", g_list_length(lst));
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
571
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
572 if (query_data->cb.txt) {
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
573 query_data->results = NULL;
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
574 query_data->cb.txt(lst, query_data->extradata);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
575 }
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
576 } else {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
577 purple_debug_error("dnssrv", "unknown query type");
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
578 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
579 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
580
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
581 query_data->resolver = NULL;
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
582 query_data->handle = 0;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
583
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
584 purple_srv_cancel(query_data);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
585
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
586 return FALSE;
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
587 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
588
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
589 static gpointer
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
590 res_thread(gpointer data)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
591 {
12451
d9feea46dac4 [gaim-migrate @ 14760]
Daniel Atallah <datallah@pidgin.im>
parents: 12439
diff changeset
592 PDNS_RECORD dr = NULL;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
593 int type;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
594 DNS_STATUS ds;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
595 PurpleSrvQueryData *query_data = data;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
596 type = query_data->type;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
597 ds = MyDnsQuery_UTF8(query_data->query, type, DNS_QUERY_STANDARD, NULL, &dr, NULL);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
598 if (ds != ERROR_SUCCESS) {
12691
4c178bccdba7 [gaim-migrate @ 15034]
Daniel Atallah <datallah@pidgin.im>
parents: 12686
diff changeset
599 gchar *msg = g_win32_error_message(ds);
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
600 if (type == DNS_TYPE_SRV) {
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
601 query_data->error_message = g_strdup_printf("Couldn't look up SRV record. %s (%lu).\n", msg, ds);
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
602 } else if (type == DNS_TYPE_TXT) {
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
603 query_data->error_message = g_strdup_printf("Couldn't look up TXT record. %s (%lu).\n", msg, ds);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
604 }
12691
4c178bccdba7 [gaim-migrate @ 15034]
Daniel Atallah <datallah@pidgin.im>
parents: 12686
diff changeset
605 g_free(msg);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
606 } else {
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
607 if (type == DNS_TYPE_SRV) {
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
608 PDNS_RECORD dr_tmp;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
609 GList *lst = NULL;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
610 DNS_SRV_DATA *srv_data;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
611 PurpleSrvResponse *srvres;
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
612
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
613 for (dr_tmp = dr; dr_tmp != NULL; dr_tmp = dr_tmp->pNext) {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
614 /* Discard any incorrect entries. I'm not sure if this is necessary */
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
615 if (dr_tmp->wType != type || strcmp(dr_tmp->pName, query_data->query) != 0) {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
616 continue;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
617 }
12451
d9feea46dac4 [gaim-migrate @ 14760]
Daniel Atallah <datallah@pidgin.im>
parents: 12439
diff changeset
618
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
619 srv_data = &dr_tmp->Data.SRV;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
620 srvres = g_new0(PurpleSrvResponse, 1);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
621 strncpy(srvres->hostname, srv_data->pNameTarget, 255);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
622 srvres->hostname[255] = '\0';
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
623 srvres->pref = srv_data->wPriority;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
624 srvres->port = srv_data->wPort;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
625 srvres->weight = srv_data->wWeight;
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
626
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
627 lst = g_list_prepend(lst, srvres);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
628 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
629
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
630 MyDnsRecordListFree(dr, DnsFreeRecordList);
27456
4f0bc5271712 Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <markdoliner@pidgin.im>
parents: 27454
diff changeset
631 query_data->results = purple_srv_sort(lst);
26970
b3dfce2dc9d3 Missed one (copying changes manually between computers is clearly an error-ful
Paul Aurich <darkrain42@pidgin.im>
parents: 26968
diff changeset
632 } else if (type == DNS_TYPE_TXT) {
26765
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
633 PDNS_RECORD dr_tmp;
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
634 GList *lst = NULL;
26765
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
635 DNS_TXT_DATA *txt_data;
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
636 PurpleTxtResponse *txtres;
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
637
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
638 for (dr_tmp = dr; dr_tmp != NULL; dr_tmp = dr_tmp->pNext) {
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
639 GString *s;
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
640 int i;
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
641
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
642 /* Discard any incorrect entries. I'm not sure if this is necessary */
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
643 if (dr_tmp->wType != type || strcmp(dr_tmp->pName, query_data->query) != 0) {
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
644 continue;
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
645 }
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
646
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
647 txt_data = &dr_tmp->Data.TXT;
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
648 txtres = g_new0(PurpleTxtResponse, 1);
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
649
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
650 s = g_string_new("");
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
651 for (i = 0; i < txt_data->dwStringCount; ++i)
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
652 s = g_string_append(s, txt_data->pStringArray[i]);
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
653 txtres->content = g_string_free(s, FALSE);
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
654
27604
15e124d441cd I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <deryni@pidgin.im>
parents: 27456
diff changeset
655 lst = g_list_append(lst, txtres);
26765
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
656 }
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
657
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
658 MyDnsRecordListFree(dr, DnsFreeRecordList);
fc156c427d59 First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <darkrain42@pidgin.im>
parents: 26531
diff changeset
659 query_data->results = lst;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
660 } else {
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
661
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
662 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
663 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
664
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
665 /* back to main thread */
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
666 /* Note: this should *not* be attached to query_data->handle - it will cause leakage */
22351
6ca0640b3d31 Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <markdoliner@pidgin.im>
parents: 22249
diff changeset
667 purple_timeout_add(0, res_main_thread_cb, query_data);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
668
12691
4c178bccdba7 [gaim-migrate @ 15034]
Daniel Atallah <datallah@pidgin.im>
parents: 12686
diff changeset
669 g_thread_exit(NULL);
4c178bccdba7 [gaim-migrate @ 15034]
Daniel Atallah <datallah@pidgin.im>
parents: 12686
diff changeset
670 return NULL;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
671 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
672
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
673 #endif
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
674
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
675 PurpleSrvQueryData *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
676 purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata)
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
677 {
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
678 char *query;
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
679 char *hostname;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
680 PurpleSrvQueryData *query_data;
26968
0527c5cc906b Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <darkrain42@pidgin.im>
parents: 26766
diff changeset
681 #ifndef _WIN32
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
682 PurpleSrvInternalQuery internal_query;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
683 int in[2], out[2];
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
684 int pid;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
685 #else
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
686 GError* err = NULL;
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
687 static gboolean initialized = FALSE;
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
688 #endif
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
689
25180
3aecff7754d5 Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents: 24672
diff changeset
690 if (!protocol || !*protocol || !transport || !*transport || !domain || !*domain) {
3aecff7754d5 Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents: 24672
diff changeset
691 purple_debug_error("dnssrv", "Wrong arguments\n");
3aecff7754d5 Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents: 24672
diff changeset
692 cb(NULL, 0, extradata);
3aecff7754d5 Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents: 24672
diff changeset
693 g_return_val_if_reached(NULL);
3aecff7754d5 Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents: 24672
diff changeset
694 }
3aecff7754d5 Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents: 24672
diff changeset
695
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
696 #ifdef USE_IDN
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
697 if (!dns_str_is_ascii(domain)) {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
698 int ret = purple_network_convert_idn_to_ascii(domain, &hostname);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
699 if (ret != 0) {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
700 purple_debug_error("dnssrv", "IDNA ToASCII failed\n");
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
701 cb(NULL, 0, extradata);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
702 return NULL;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
703 }
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
704 } else /* Fallthru is intentional */
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
705 #endif
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
706 hostname = g_strdup(domain);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
707
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
708 query = g_strdup_printf("_%s._%s.%s", protocol, transport, hostname);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
709 purple_debug_info("dnssrv","querying SRV record for %s: %s\n", domain,
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
710 query);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
711 g_free(hostname);
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
712
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
713 #ifndef _WIN32
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
714 if(pipe(in) || pipe(out)) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
715 purple_debug_error("dnssrv", "Could not create pipe\n");
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
716 g_free(query);
11382
4458ab177b10 [gaim-migrate @ 13609]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11381
diff changeset
717 cb(NULL, 0, extradata);
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
718 return NULL;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
719 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
720
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
721 pid = fork();
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
722 if (pid == -1) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
723 purple_debug_error("dnssrv", "Could not create process!\n");
11382
4458ab177b10 [gaim-migrate @ 13609]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11381
diff changeset
724 cb(NULL, 0, extradata);
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
725 g_free(query);
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
726 return NULL;
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
727 }
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
728
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
729 /* Child */
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
730 if (pid == 0)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
731 {
22249
18041843e873 Fix a memleak that doesn't matter because it's in a child process
Mark Doliner <markdoliner@pidgin.im>
parents: 22234
diff changeset
732 g_free(query);
18041843e873 Fix a memleak that doesn't matter because it's in a child process
Mark Doliner <markdoliner@pidgin.im>
parents: 22234
diff changeset
733
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
734 close(out[0]);
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
735 close(in[1]);
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
736 resolve(in[0], out[1]);
22249
18041843e873 Fix a memleak that doesn't matter because it's in a child process
Mark Doliner <markdoliner@pidgin.im>
parents: 22234
diff changeset
737 /* resolve() does not return */
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
738 }
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
739
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
740 close(out[1]);
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
741 close(in[0]);
11395
1b19bd77adf6 [gaim-migrate @ 13626]
Daniel Atallah <datallah@pidgin.im>
parents: 11382
diff changeset
742
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
743 internal_query.type = T_SRV;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
744 strncpy(internal_query.query, query, 255);
28612
5f60e92c2f49 Null-terminate this string explicitly to avoid valgrind complaining.
Paul Aurich <darkrain42@pidgin.im>
parents: 28291
diff changeset
745 internal_query.query[255] = '\0';
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
746
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
747 if (write(in[1], &internal_query, sizeof(internal_query)) < 0)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
748 purple_debug_error("dnssrv", "Could not write to SRV resolver\n");
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
749
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
750 query_data = g_new0(PurpleSrvQueryData, 1);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
751 query_data->type = T_SRV;
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
752 query_data->cb.srv = cb;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
753 query_data->extradata = extradata;
15776
cba54f9d2e51 Patch from Graham Booker which ensures that a process forked by dnsserv cleans up afterwards, calling waitpid() to make sure no zombies are left over.
Evan Schoenberg <evands@pidgin.im>
parents: 15718
diff changeset
754 query_data->pid = pid;
20128
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
755 query_data->fd_out = out[0];
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
756 query_data->fd_in = in[1];
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
757 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data);
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
758
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
759 g_free(query);
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
760
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
761 return query_data;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
762 #else
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
763 if (!initialized) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
764 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
765 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc(
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
766 "dnsapi.dll", "DnsRecordListFree");
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
767 initialized = TRUE;
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
768 }
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
769
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
770 query_data = g_new0(PurpleSrvQueryData, 1);
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
771 query_data->type = DNS_TYPE_SRV;
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
772 query_data->cb.srv = cb;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
773 query_data->query = query;
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
774 query_data->extradata = extradata;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
775
15859
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
776 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree)
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
777 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n");
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
778 else {
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
779 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err);
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
780 if (query_data->resolver == NULL) {
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
781 query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", (err && err->message) ? err->message : "");
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
782 g_error_free(err);
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
783 }
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
784 }
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
785
15859
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
786 /* The query isn't going to happen, so finish the SRV lookup now.
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
787 * Asynchronously call the callback since stuff may not expect
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
788 * the callback to be called before this returns */
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
789 if (query_data->error_message != NULL)
22351
6ca0640b3d31 Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <markdoliner@pidgin.im>
parents: 22249
diff changeset
790 query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data);
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
791
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
792 return query_data;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
793 #endif
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
794 }
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
795
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
796 PurpleSrvQueryData *purple_txt_resolve(const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata)
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
797 {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
798 char *query;
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
799 char *hostname;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
800 PurpleSrvQueryData *query_data;
26968
0527c5cc906b Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <darkrain42@pidgin.im>
parents: 26766
diff changeset
801 #ifndef _WIN32
23605
8d2e64e9208e * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23604
diff changeset
802 PurpleSrvInternalQuery internal_query;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
803 int in[2], out[2];
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
804 int pid;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
805 #else
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
806 GError* err = NULL;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
807 static gboolean initialized = FALSE;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
808 #endif
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
809
27898
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
810 #ifdef USE_IDN
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
811 if (!dns_str_is_ascii(domain)) {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
812 int ret = purple_network_convert_idn_to_ascii(domain, &hostname);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
813 if (ret != 0) {
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
814 purple_debug_error("dnssrv", "IDNA ToASCII failed\n");
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
815 cb(NULL, extradata);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
816 return NULL;
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
817 }
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
818 } else /* fallthru is intentional */
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
819 #endif
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
820 hostname = g_strdup(domain);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
821
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
822 query = g_strdup_printf("%s.%s", owner, hostname);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
823 purple_debug_info("dnssrv","querying TXT record for %s: %s\n", domain,
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
824 query);
4a6450d92e11 Move the IDN support into the DNS routines.
Paul Aurich <darkrain42@pidgin.im>
parents: 27604
diff changeset
825 g_free(hostname);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
826
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
827 #ifndef _WIN32
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
828 if(pipe(in) || pipe(out)) {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
829 purple_debug_error("dnssrv", "Could not create pipe\n");
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
830 g_free(query);
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
831 cb(NULL, extradata);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
832 return NULL;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
833 }
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
834
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
835 pid = fork();
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
836 if (pid == -1) {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
837 purple_debug_error("dnssrv", "Could not create process!\n");
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
838 cb(NULL, extradata);
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
839 g_free(query);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
840 return NULL;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
841 }
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
842
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
843 /* Child */
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
844 if (pid == 0)
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
845 {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
846 g_free(query);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
847
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
848 close(out[0]);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
849 close(in[1]);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
850 resolve(in[0], out[1]);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
851 /* resolve() does not return */
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
852 }
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
853
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
854 close(out[1]);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
855 close(in[0]);
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
856
23605
8d2e64e9208e * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23604
diff changeset
857 internal_query.type = T_TXT;
8d2e64e9208e * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23604
diff changeset
858 strncpy(internal_query.query, query, 255);
28675
88bea0ad71ad Shut up valgrind ("unitialized bytes(s)...") and changelog.
Paul Aurich <darkrain42@pidgin.im>
parents: 28674
diff changeset
859 internal_query.query[255] = '\0';
27454
e950ec66bb5e Strip trailing whitespace and spaces to tab
Mark Doliner <markdoliner@pidgin.im>
parents: 27157
diff changeset
860
23605
8d2e64e9208e * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23604
diff changeset
861 if (write(in[1], &internal_query, sizeof(internal_query)) < 0)
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
862 purple_debug_error("dnssrv", "Could not write to TXT resolver\n");
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
863
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
864 query_data = g_new0(PurpleSrvQueryData, 1);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
865 query_data->type = T_TXT;
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
866 query_data->cb.txt = cb;
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
867 query_data->extradata = extradata;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
868 query_data->pid = pid;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
869 query_data->fd_out = out[0];
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
870 query_data->fd_in = in[1];
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
871 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
872
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
873 g_free(query);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
874
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
875 return query_data;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
876 #else
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
877 if (!initialized) {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
878 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
879 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc(
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
880 "dnsapi.dll", "DnsRecordListFree");
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
881 initialized = TRUE;
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
882 }
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
883
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
884 query_data = g_new0(PurpleSrvQueryData, 1);
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
885 query_data->type = DNS_TYPE_TXT;
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
886 query_data->cb.txt = cb;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
887 query_data->query = query;
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
888 query_data->extradata = extradata;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
889
15859
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
890 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree)
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
891 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n");
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
892 else {
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
893 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err);
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
894 if (query_data->resolver == NULL) {
24744
cc73361014f6 Cut-n-paste typo
Paul Aurich <darkrain42@pidgin.im>
parents: 24743
diff changeset
895 query_data->error_message = g_strdup_printf("TXT thread create failure: %s\n", (err && err->message) ? err->message : "");
15859
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
896 g_error_free(err);
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
897 }
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
898 }
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
899
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
900 /* The query isn't going to happen, so finish the TXT lookup now.
15859
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
901 * Asynchronously call the callback since stuff may not expect
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
902 * the callback to be called before this returns */
98b7f9bf8e28 Minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents: 15776
diff changeset
903 if (query_data->error_message != NULL)
22351
6ca0640b3d31 Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <markdoliner@pidgin.im>
parents: 22249
diff changeset
904 query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data);
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
905
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
906 return query_data;
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
907 #endif
11373
80fd6df6fbe0 [gaim-migrate @ 13598]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
908 }
11379
a5a66b0e8b6e [gaim-migrate @ 13605]
Daniel Atallah <datallah@pidgin.im>
parents: 11373
diff changeset
909
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
910 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
911 purple_srv_cancel(PurpleSrvQueryData *query_data)
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
912 {
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
913 if (query_data->handle > 0)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15776
diff changeset
914 purple_input_remove(query_data->handle);
14374
a93eedc7aa6b [gaim-migrate @ 17002]
Daniel Atallah <datallah@pidgin.im>
parents: 14370
diff changeset
915 #ifdef _WIN32
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
916 if (query_data->resolver != NULL)
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
917 {
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
918 /*
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
919 * It's not really possible to kill a thread. So instead we
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
920 * just set the callback to NULL and let the DNS lookup
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
921 * finish.
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
922 */
24743
4762054cf996 dnssrv.c:
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
923 query_data->cb.srv = NULL;
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
924 return;
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
925 }
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
926 g_free(query_data->query);
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
927 g_free(query_data->error_message);
20128
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
928 #else
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
929 close(query_data->fd_out);
272326eb883e applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
930 close(query_data->fd_in);
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
931 #endif
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
932 g_free(query_data);
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
933 }
23604
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
934
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
935 void
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
936 purple_txt_cancel(PurpleSrvQueryData *query_data)
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
937 {
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
938 purple_srv_cancel(query_data);
f34d41640be2 * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23352
diff changeset
939 }
26766
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
940
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
941 const gchar *
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
942 purple_txt_response_get_content(PurpleTxtResponse *resp)
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
943 {
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
944 g_return_val_if_fail(resp != NULL, NULL);
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
945
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
946 return resp->content;
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
947 }
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
948
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
949 void purple_txt_response_destroy(PurpleTxtResponse *resp)
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
950 {
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
951 g_return_if_fail(resp != NULL);
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
952
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
953 g_free(resp->content);
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
954 g_free(resp);
854a2eaa3862 Hide PurpleTxtResponse and use a more purple API
Paul Aurich <darkrain42@pidgin.im>
parents: 26765
diff changeset
955 }

mercurial