Mercurial > pidgin.yaz
annotate libpurple/dnssrv.c @ 28091:fd781c98a360
Oops.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 31 Jul 2009 04:15:02 +0000 |
parents | 7fbf964c6c6c |
children | bbb9e0ea67fe |
rev | line source |
---|---|
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1 /** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2 * @file dnssrv.c |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
3 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
4 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
5 /* purple |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
6 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
7 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
8 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
9 * This program is free software; you can redistribute it and/or modify |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
12 * (at your option) any later version. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
13 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
17 * GNU General Public License for more details. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
18 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
20 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18401
diff
changeset
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
22 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
23 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
24 #include "internal.h" |
15657
ca1c878be941
Include util.h to fix a warning I introduced
Evan Schoenberg <evan.s@dreskin.net>
parents:
15646
diff
changeset
|
25 #include "util.h" |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
26 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
27 #ifndef _WIN32 |
23203
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22224
diff
changeset
|
28 #include <arpa/nameser.h> |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
29 #include <resolv.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
30 #ifdef HAVE_ARPA_NAMESER_COMPAT_H |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
31 #include <arpa/nameser_compat.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
32 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
33 #ifndef T_SRV |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
34 #define T_SRV 33 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
35 #endif |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
36 #ifndef T_TXT |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
37 #define T_TXT 16 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
38 #endif |
25766 | 39 #else /* WIN32 */ |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 #include <windns.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
41 /* Missing from the mingw headers */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 #ifndef DNS_TYPE_SRV |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
43 # define DNS_TYPE_SRV 33 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
44 #endif |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
45 #ifndef DNS_TYPE_TXT |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
46 # define DNS_TYPE_TXT 16 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
47 #endif |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
48 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
49 |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
50 #include "debug.h" |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
51 #include "dnssrv.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
52 #include "eventloop.h" |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
53 #include "network.h" |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
55 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 typedef union { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 HEADER hdr; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 u_char buf[1024]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
59 } queryans; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
60 #else |
18401
3c6bc8785af9
Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents:
16914
diff
changeset
|
61 static DNS_STATUS (WINAPI *MyDnsQuery_UTF8) ( |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
62 PCSTR lpstrName, WORD wType, DWORD fOptions, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 PIP4_ARRAY aipServers, PDNS_RECORD* ppQueryResultsSet, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
64 PVOID* pReserved) = NULL; |
18401
3c6bc8785af9
Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents:
16914
diff
changeset
|
65 static void (WINAPI *MyDnsRecordListFree) (PDNS_RECORD pRecordList, |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
66 DNS_FREE_TYPE FreeType) = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
67 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
68 |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
69 struct _PurpleTxtResponse { |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
70 char *content; |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
71 }; |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
72 |
15823 | 73 struct _PurpleSrvQueryData { |
25766 | 74 union { |
75 PurpleSrvCallback srv; | |
76 PurpleTxtCallback txt; | |
77 } cb; | |
78 | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
79 gpointer extradata; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
80 guint handle; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
81 int type; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
82 #ifdef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
83 GThread *resolver; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
84 char *query; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
85 char *error_message; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
86 GList *results; |
15713
4530f15fe5af
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 <evan.s@dreskin.net>
parents:
15657
diff
changeset
|
87 #else |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
88 int fd_in, fd_out; |
15713
4530f15fe5af
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 <evan.s@dreskin.net>
parents:
15657
diff
changeset
|
89 pid_t pid; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
90 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
91 }; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
92 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
93 typedef struct _PurpleSrvInternalQuery { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
94 int type; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
95 char query[256]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
96 } PurpleSrvInternalQuery; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
97 |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
98 typedef struct _PurpleSrvResponseContainer { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
99 PurpleSrvResponse *response; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
100 int sum; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
101 } PurpleSrvResponseContainer; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
102 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
103 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
104 * Sort by priority, then by weight. Strictly numerically--no |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
105 * randomness. Technically we only need to sort by pref and then |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
106 * make sure any records with weight 0 are at the beginning of |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
107 * their group, but it's just as easy to sort by weight. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
108 */ |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
109 static gint |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
110 responsecompare(gconstpointer ar, gconstpointer br) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
111 { |
15823 | 112 PurpleSrvResponse *a = (PurpleSrvResponse*)ar; |
113 PurpleSrvResponse *b = (PurpleSrvResponse*)br; | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
114 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
115 if(a->pref == b->pref) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
116 if(a->weight == b->weight) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
117 return 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
118 if(a->weight < b->weight) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
119 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
120 return 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
122 if(a->pref < b->pref) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
123 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
124 return 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
125 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
126 |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
127 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
128 * Iterate over a list of PurpleSrvResponseContainer making the sum |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
129 * the running total of the sums. Select a random integer in the range |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
130 * (1, sum+1), then find the first element greater than or equal to the |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
131 * number selected. From RFC 2782. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
132 * |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
133 * @param list The list of PurpleSrvResponseContainer. This function |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
134 * removes a node from this list and returns the new list. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
135 * @param container_ptr The PurpleSrvResponseContainer that was chosen |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
136 * will be returned here. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
137 */ |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
138 static GList * |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
139 select_random_response(GList *list, PurpleSrvResponseContainer **container_ptr) |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
140 { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
141 GList *cur; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
142 size_t runningtotal; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
143 int r; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
144 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
145 runningtotal = 0; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
146 cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
147 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
148 while (cur) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
149 PurpleSrvResponseContainer *container = cur->data; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
150 runningtotal += container->response->weight; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
151 container->sum = runningtotal; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
152 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
153 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
154 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
155 /* |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
156 * If the running total is greater than 0, pick a number between |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
157 * 1 and the runningtotal inclusive. (This is not precisely what |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
158 * the RFC algorithm describes, but we wish to deal with integers |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
159 * and avoid floats. This is functionally equivalent.) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
160 * If running total is 0, then choose r = 0. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
161 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
162 r = runningtotal ? g_random_int_range(1, runningtotal + 1) : 0; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
163 cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
164 while (r > ((PurpleSrvResponseContainer *)cur->data)->sum) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
165 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
166 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
167 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
168 /* Set the return parameter and remove cur from the list */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
169 *container_ptr = cur->data; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
170 return g_list_delete_link(list, cur); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
171 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
172 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
173 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
174 * Reorder a GList of PurpleSrvResponses that have the same priority |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
175 * (aka "pref"). |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
176 */ |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
177 static void |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
178 srv_reorder(GList *list, int num) |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
179 { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
180 int i; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
181 GList *cur, *container_list = NULL; |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
182 PurpleSrvResponseContainer *container; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
183 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
184 if (num < 2) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
185 /* Nothing to sort */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
186 return; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
187 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
188 /* First build a list of container structs */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
189 for (i = 0, cur = list; i < num; i++, cur = cur->next) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
190 container = g_new(PurpleSrvResponseContainer, 1); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
191 container->response = cur->data; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
192 container_list = g_list_prepend(container_list, container); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
193 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
194 container_list = g_list_reverse(container_list); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
195 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
196 /* |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
197 * Re-order the list that was passed in as a parameter. We leave |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
198 * the list nodes in place, but replace their data pointers. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
199 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
200 cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
201 while (container_list) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
202 container_list = select_random_response(container_list, &container); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
203 cur->data = container->response; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
204 g_free(container); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
205 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
206 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
207 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
208 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
209 /** |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
210 * Sorts a GList of PurpleSrvResponses according to the |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
211 * algorithm described in RFC 2782. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
212 * |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
213 * @param response GList of PurpleSrvResponse's |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
214 * @param The original list, resorted |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
215 */ |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
216 static GList * |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
217 purple_srv_sort(GList *list) |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
218 { |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
219 int pref, count; |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
220 GList *cur, *start; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
221 |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
222 if (!list || !list->next) { |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
223 /* Nothing to sort */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
224 return list; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
225 } |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
226 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
227 list = g_list_sort(list, responsecompare); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
228 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
229 start = cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
230 count = 1; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
231 while (cur) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
232 PurpleSrvResponse *next_response; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
233 pref = ((PurpleSrvResponse *)cur->data)->pref; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
234 next_response = cur->next ? cur->next->data : NULL; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
235 if (!next_response || next_response->pref != pref) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
236 /* |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
237 * The 'count' records starting at 'start' all have the same |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
238 * priority. Sort them by weight. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
239 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
240 srv_reorder(start, count); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
241 start = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
242 count = 0; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
243 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
244 count++; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
245 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
246 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
247 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
248 return list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
249 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
250 |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
251 static gboolean |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
252 dns_str_is_ascii(const char *name) |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
253 { |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
254 guchar *c; |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
255 for (c = (guchar *)name; c && *c; ++c) { |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
256 if (*c > 0x7f) |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
257 return FALSE; |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
258 } |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
259 |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
260 return TRUE; |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
261 } |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
262 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
263 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
264 |
16642
c028fc690b5d
Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents:
15829
diff
changeset
|
265 G_GNUC_NORETURN static void |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
266 resolve(int in, int out) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
267 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
268 GList *ret = NULL; |
15823 | 269 PurpleSrvResponse *srvres; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
270 PurpleTxtResponse *txtres; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
271 queryans answer; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
272 int size, qdcount, ancount; |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
273 guchar *end, *cp; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
274 gchar name[256]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
275 guint16 type, dlen, pref, weight, port; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
276 PurpleSrvInternalQuery query; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
277 |
15646
61b42cf81aa4
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 <evan.s@dreskin.net>
parents:
15374
diff
changeset
|
278 #ifdef HAVE_SIGNAL_H |
15823 | 279 purple_restore_default_signal_handlers(); |
15646
61b42cf81aa4
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 <evan.s@dreskin.net>
parents:
15374
diff
changeset
|
280 #endif |
15800 | 281 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
282 if (read(in, &query, sizeof(query)) <= 0) { |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
283 close(out); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
284 close(in); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
285 _exit(0); |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
286 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
287 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
288 size = res_query( query.query, C_IN, query.type, (u_char*)&answer, sizeof( answer)); |
27016
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
289 if (size == -1) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
290 write(out, &(query.type), sizeof(query.type)); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
291 write(out, &size, sizeof(int)); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
292 close(out); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
293 close(in); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
294 _exit(0); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
295 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
296 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
297 qdcount = ntohs(answer.hdr.qdcount); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
298 ancount = ntohs(answer.hdr.ancount); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
299 cp = (guchar*)&answer + sizeof(HEADER); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
300 end = (guchar*)&answer + size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
301 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
302 /* skip over unwanted stuff */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
303 while (qdcount-- > 0 && cp < end) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
304 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
305 if(size < 0) goto end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
306 cp += size + QFIXEDSZ; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
307 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
308 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
309 while (ancount-- > 0 && cp < end) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
310 size = dn_expand((unsigned char*)&answer, end, cp, name, 256); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
311 if(size < 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
312 goto end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
313 cp += size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
314 GETSHORT(type,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
315 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
316 /* skip ttl and class since we already know it */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
317 cp += 6; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
318 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
319 GETSHORT(dlen,cp); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
320 if (query.type == T_SRV) { |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
321 GETSHORT(pref,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
322 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
323 GETSHORT(weight,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
324 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
325 GETSHORT(port,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
326 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
327 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
328 if(size < 0 ) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
329 goto end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
330 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
331 cp += size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
332 |
15823 | 333 srvres = g_new0(PurpleSrvResponse, 1); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
334 strcpy(srvres->hostname, name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
335 srvres->pref = pref; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
336 srvres->port = port; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
337 srvres->weight = weight; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
338 |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
339 ret = g_list_prepend(ret, srvres); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
340 } else if (query.type == T_TXT) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
341 txtres = g_new0(PurpleTxtResponse, 1); |
26671
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
342 txtres->content = g_strndup((gchar*)(++cp), dlen-1); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
343 ret = g_list_append(ret, txtres); |
25595
94c8bef52c66
* some further bugfixing, BIND's libresolv does so much for the programmer, just happy it exists
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25594
diff
changeset
|
344 cp += dlen - 1; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
345 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
346 cp += dlen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
347 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
348 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
349 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
350 end: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
351 size = g_list_length(ret); |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
352 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
353 if (query.type == T_SRV) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
354 ret = purple_srv_sort(ret); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
355 |
26271 | 356 /* TODO: Check return value */ |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
357 write(out, &(query.type), sizeof(query.type)); |
25594
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25593
diff
changeset
|
358 write(out, &size, sizeof(size)); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
359 while (ret != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
360 { |
26271 | 361 /* TODO: Check return value */ |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
362 if (query.type == T_SRV) |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
363 write(out, ret->data, sizeof(PurpleSrvResponse)); |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
364 if (query.type == T_TXT) |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
365 write(out, ret->data, sizeof(PurpleTxtResponse)); |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
366 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
367 g_free(ret->data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
368 ret = g_list_remove(ret, ret->data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
369 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
370 |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
371 close(out); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
372 close(in); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
373 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
374 _exit(0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
375 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
376 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
377 static void |
15823 | 378 resolved(gpointer data, gint source, PurpleInputCondition cond) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
379 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
380 int size; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
381 int type; |
15823 | 382 PurpleSrvQueryData *query_data = (PurpleSrvQueryData*)data; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
383 int i; |
15713
4530f15fe5af
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 <evan.s@dreskin.net>
parents:
15657
diff
changeset
|
384 int status; |
27016
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
385 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
386 if (read(source, &type, sizeof(type)) == sizeof(type)) { |
27016
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
387 if (read(source, &size, sizeof(size)) == sizeof(size)) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
388 if (size == -1 || size == 0) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
389 if (size == -1) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
390 purple_debug_warning("dnssrv", "res_query returned an error\n"); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
391 /* Re-read resolv.conf and friends in case DNS servers have changed */ |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
392 res_init(); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
393 } else |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
394 purple_debug_info("dnssrv", "Found 0 entries, errno is %i\n", errno); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
395 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
396 if (type == T_SRV) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
397 PurpleSrvCallback cb = query_data->cb.srv; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
398 cb(NULL, 0, query_data->extradata); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
399 } else if (type == T_TXT) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
400 PurpleTxtCallback cb = query_data->cb.txt; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
401 cb(NULL, query_data->extradata); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
402 } else { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
403 purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
404 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
405 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
406 } else if (size) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
407 if (type == T_SRV) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
408 PurpleSrvResponse *res; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
409 PurpleSrvResponse *tmp; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
410 PurpleSrvCallback cb = query_data->cb.srv; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
411 ssize_t red; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
412 purple_debug_info("dnssrv","found %d SRV entries\n", size); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
413 tmp = res = g_new0(PurpleSrvResponse, size); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
414 for (i = 0; i < size; i++) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
415 red = read(source, tmp++, sizeof(PurpleSrvResponse)); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
416 if (red != sizeof(PurpleSrvResponse)) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
417 purple_debug_error("dnssrv","unable to read srv " |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
418 "response: %s\n", g_strerror(errno)); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
419 size = 0; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
420 g_free(res); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
421 res = NULL; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
422 } |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
423 } |
27016
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
424 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
425 cb(res, size, query_data->extradata); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
426 } else if (type == T_TXT) { |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
427 GList *responses = NULL; |
27016
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
428 PurpleTxtResponse *res; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
429 PurpleTxtCallback cb = query_data->cb.txt; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
430 ssize_t red; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
431 purple_debug_info("dnssrv","found %d TXT entries\n", size); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
432 res = g_new0(PurpleTxtResponse, 1); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
433 for (i = 0; i < size; i++) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
434 red = read(source, res, sizeof(PurpleTxtResponse)); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
435 if (red != sizeof(PurpleTxtResponse)) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
436 purple_debug_error("dnssrv","unable to read txt " |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
437 "response: %s\n", g_strerror(errno)); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
438 size = 0; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
439 g_free(res); |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
440 g_list_foreach(responses, (GFunc)purple_txt_response_destroy, NULL); |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
441 g_list_free(responses); |
27016
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
442 responses = NULL; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
443 break; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
444 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
445 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
446 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
447 cb(responses, query_data->extradata); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
448 } else { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26829
diff
changeset
|
449 purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
450 } |
22107
bfe1854bbf87
More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents:
20636
diff
changeset
|
451 } |
16914
11a0f2b4ac83
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 <evan.s@dreskin.net>
parents:
16642
diff
changeset
|
452 } |
11a0f2b4ac83
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 <evan.s@dreskin.net>
parents:
16642
diff
changeset
|
453 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
454 |
15713
4530f15fe5af
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 <evan.s@dreskin.net>
parents:
15657
diff
changeset
|
455 waitpid(query_data->pid, &status, 0); |
15823 | 456 purple_srv_cancel(query_data); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
457 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
458 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
459 #else /* _WIN32 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
460 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
461 /** The Jabber Server code was inspiration for parts of this. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
462 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
463 static gboolean |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
464 res_main_thread_cb(gpointer data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
465 { |
15823 | 466 PurpleSrvResponse *srvres = NULL; |
467 PurpleSrvQueryData *query_data = data; | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
468 if(query_data->error_message != NULL) |
15823 | 469 purple_debug_error("dnssrv", query_data->error_message); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
470 else { |
26827
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26672
diff
changeset
|
471 if (query_data->type == DNS_TYPE_SRV) { |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
472 PurpleSrvResponse *srvres_tmp = NULL; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
473 GList *lst = query_data->results; |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
474 int size = g_list_length(lst); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
475 |
25766 | 476 if(query_data->cb.srv && size > 0) |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
477 srvres_tmp = srvres = g_new0(PurpleSrvResponse, size); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
478 while (lst) { |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
479 PurpleSrvResponse *lstdata = lst->data; |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
480 lst = g_list_delete_link(lst, lst); |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
481 |
25766 | 482 if(query_data->cb.srv) |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
483 memcpy(srvres_tmp++, lstdata, sizeof(PurpleSrvResponse)); |
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
484 g_free(lstdata); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
485 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
486 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
487 query_data->results = NULL; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
488 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
489 purple_debug_info("dnssrv", "found %d SRV entries\n", size); |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
490 |
25766 | 491 if(query_data->cb.srv) query_data->cb.srv(srvres, size, query_data->extradata); |
26827
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26672
diff
changeset
|
492 } else if (query_data->type == DNS_TYPE_TXT) { |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
493 GList *lst = query_data->results; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
494 |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
495 purple_debug_info("dnssrv", "found %d TXT entries\n", g_list_length(lst)); |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
496 |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
497 if (query_data->cb.txt) { |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
498 query_data->results = NULL; |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
499 query_data->cb.txt(lst, query_data->extradata); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
500 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
501 } else { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
502 purple_debug_error("dnssrv", "unknown query type"); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
503 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
504 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
505 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
506 query_data->resolver = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
507 query_data->handle = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
508 |
15823 | 509 purple_srv_cancel(query_data); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
510 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
511 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
512 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
513 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
514 static gpointer |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
515 res_thread(gpointer data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
516 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
517 PDNS_RECORD dr = NULL; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
518 int type; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
519 DNS_STATUS ds; |
15823 | 520 PurpleSrvQueryData *query_data = data; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
521 type = query_data->type; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
522 ds = MyDnsQuery_UTF8(query_data->query, type, DNS_QUERY_STANDARD, NULL, &dr, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
523 if (ds != ERROR_SUCCESS) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
524 gchar *msg = g_win32_error_message(ds); |
25766 | 525 if (type == DNS_TYPE_SRV) { |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
526 query_data->error_message = g_strdup_printf("Couldn't look up SRV record. %s (%lu).\n", msg, ds); |
25766 | 527 } else if (type == DNS_TYPE_TXT) { |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
528 query_data->error_message = g_strdup_printf("Couldn't look up TXT record. %s (%lu).\n", msg, ds); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
529 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
530 g_free(msg); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
531 } else { |
25766 | 532 if (type == DNS_TYPE_SRV) { |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
533 PDNS_RECORD dr_tmp; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
534 GList *lst = NULL; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
535 DNS_SRV_DATA *srv_data; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
536 PurpleSrvResponse *srvres; |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
537 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
538 for (dr_tmp = dr; dr_tmp != NULL; dr_tmp = dr_tmp->pNext) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
539 /* Discard any incorrect entries. I'm not sure if this is necessary */ |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
540 if (dr_tmp->wType != type || strcmp(dr_tmp->pName, query_data->query) != 0) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
541 continue; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
542 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
543 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
544 srv_data = &dr_tmp->Data.SRV; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
545 srvres = g_new0(PurpleSrvResponse, 1); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
546 strncpy(srvres->hostname, srv_data->pNameTarget, 255); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
547 srvres->hostname[255] = '\0'; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
548 srvres->pref = srv_data->wPriority; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
549 srvres->port = srv_data->wPort; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
550 srvres->weight = srv_data->wWeight; |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
551 |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
552 lst = g_list_prepend(lst, srvres); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
553 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
554 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
555 MyDnsRecordListFree(dr, DnsFreeRecordList); |
27295
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27294
diff
changeset
|
556 query_data->results = purple_srv_sort(lst); |
26829
7b0231e5c818
Missed one (copying changes manually between computers is clearly an error-ful
Paul Aurich <paul@darkrain42.org>
parents:
26827
diff
changeset
|
557 } else if (type == DNS_TYPE_TXT) { |
26671
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
558 PDNS_RECORD dr_tmp; |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
559 GList *lst = NULL; |
26671
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
560 DNS_TXT_DATA *txt_data; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
561 PurpleTxtResponse *txtres; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
562 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
563 for (dr_tmp = dr; dr_tmp != NULL; dr_tmp = dr_tmp->pNext) { |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
564 GString *s; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
565 int i; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
566 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
567 /* Discard any incorrect entries. I'm not sure if this is necessary */ |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
568 if (dr_tmp->wType != type || strcmp(dr_tmp->pName, query_data->query) != 0) { |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
569 continue; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
570 } |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
571 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
572 txt_data = &dr_tmp->Data.TXT; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
573 txtres = g_new0(PurpleTxtResponse, 1); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
574 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
575 s = g_string_new(""); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
576 for (i = 0; i < txt_data->dwStringCount; ++i) |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
577 s = g_string_append(s, txt_data->pStringArray[i]); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
578 txtres->content = g_string_free(s, FALSE); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
579 |
27430
e400cd35542b
I was seeing some crashes when connecting to Google Talk on my work laptop.
Etan Reisner <pidgin@unreliablesource.net>
parents:
27295
diff
changeset
|
580 lst = g_list_append(lst, txtres); |
26671
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
581 } |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
582 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
583 MyDnsRecordListFree(dr, DnsFreeRecordList); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26352
diff
changeset
|
584 query_data->results = lst; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
585 } else { |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
586 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
587 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
588 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
589 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
590 /* back to main thread */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
591 /* Note: this should *not* be attached to query_data->handle - it will cause leakage */ |
22224
d1b36a8c920a
Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <mark@kingant.net>
parents:
22124
diff
changeset
|
592 purple_timeout_add(0, res_main_thread_cb, query_data); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
593 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
594 g_thread_exit(NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
595 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
596 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
597 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
598 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
599 |
15823 | 600 PurpleSrvQueryData * |
601 purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata) | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
602 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
603 char *query; |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
604 char *hostname; |
15823 | 605 PurpleSrvQueryData *query_data; |
26827
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26672
diff
changeset
|
606 #ifndef _WIN32 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
607 PurpleSrvInternalQuery internal_query; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
608 int in[2], out[2]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
609 int pid; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
610 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
611 GError* err = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
612 static gboolean initialized = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
613 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
614 |
24698
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24394
diff
changeset
|
615 if (!protocol || !*protocol || !transport || !*transport || !domain || !*domain) { |
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24394
diff
changeset
|
616 purple_debug_error("dnssrv", "Wrong arguments\n"); |
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24394
diff
changeset
|
617 cb(NULL, 0, extradata); |
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24394
diff
changeset
|
618 g_return_val_if_reached(NULL); |
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24394
diff
changeset
|
619 } |
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24394
diff
changeset
|
620 |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
621 #ifdef USE_IDN |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
622 if (!dns_str_is_ascii(domain)) { |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
623 int ret = purple_network_convert_idn_to_ascii(domain, &hostname); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
624 if (ret != 0) { |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
625 purple_debug_error("dnssrv", "IDNA ToASCII failed\n"); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
626 cb(NULL, 0, extradata); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
627 return NULL; |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
628 } |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
629 } else /* Fallthru is intentional */ |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
630 #endif |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
631 hostname = g_strdup(domain); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
632 |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
633 query = g_strdup_printf("_%s._%s.%s", protocol, transport, hostname); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
634 purple_debug_info("dnssrv","querying SRV record for %s: %s\n", domain, |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
635 query); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
636 g_free(hostname); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
637 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
638 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
639 if(pipe(in) || pipe(out)) { |
15823 | 640 purple_debug_error("dnssrv", "Could not create pipe\n"); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
641 g_free(query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
642 cb(NULL, 0, extradata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
643 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
644 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
645 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
646 pid = fork(); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
647 if (pid == -1) { |
15823 | 648 purple_debug_error("dnssrv", "Could not create process!\n"); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
649 cb(NULL, 0, extradata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
650 g_free(query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
651 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
652 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
653 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
654 /* Child */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
655 if (pid == 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
656 { |
22124
df77b89a4025
Fix a memleak that doesn't matter because it's in a child process
Mark Doliner <mark@kingant.net>
parents:
22107
diff
changeset
|
657 g_free(query); |
df77b89a4025
Fix a memleak that doesn't matter because it's in a child process
Mark Doliner <mark@kingant.net>
parents:
22107
diff
changeset
|
658 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
659 close(out[0]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
660 close(in[1]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
661 resolve(in[0], out[1]); |
22124
df77b89a4025
Fix a memleak that doesn't matter because it's in a child process
Mark Doliner <mark@kingant.net>
parents:
22107
diff
changeset
|
662 /* resolve() does not return */ |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
663 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
664 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
665 close(out[1]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
666 close(in[0]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
667 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
668 internal_query.type = T_SRV; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
669 strncpy(internal_query.query, query, 255); |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
670 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
671 if (write(in[1], &internal_query, sizeof(internal_query)) < 0) |
15823 | 672 purple_debug_error("dnssrv", "Could not write to SRV resolver\n"); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
673 |
15823 | 674 query_data = g_new0(PurpleSrvQueryData, 1); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
675 query_data->type = T_SRV; |
25766 | 676 query_data->cb.srv = cb; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
677 query_data->extradata = extradata; |
15713
4530f15fe5af
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 <evan.s@dreskin.net>
parents:
15657
diff
changeset
|
678 query_data->pid = pid; |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
679 query_data->fd_out = out[0]; |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
680 query_data->fd_in = in[1]; |
15823 | 681 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
682 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
683 g_free(query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
684 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
685 return query_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
686 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
687 if (!initialized) { |
15823 | 688 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8"); |
689 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc( | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
690 "dnsapi.dll", "DnsRecordListFree"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
691 initialized = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
692 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
693 |
15823 | 694 query_data = g_new0(PurpleSrvQueryData, 1); |
25766 | 695 query_data->type = DNS_TYPE_SRV; |
696 query_data->cb.srv = cb; | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
697 query_data->query = query; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
698 query_data->extradata = extradata; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
699 |
15800 | 700 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) |
701 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n"); | |
702 else { | |
703 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err); | |
704 if (query_data->resolver == NULL) { | |
705 query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", (err && err->message) ? err->message : ""); | |
706 g_error_free(err); | |
707 } | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
708 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
709 |
15800 | 710 /* The query isn't going to happen, so finish the SRV lookup now. |
711 * Asynchronously call the callback since stuff may not expect | |
712 * the callback to be called before this returns */ | |
713 if (query_data->error_message != NULL) | |
22224
d1b36a8c920a
Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <mark@kingant.net>
parents:
22124
diff
changeset
|
714 query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
715 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
716 return query_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
717 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
718 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
719 |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
720 PurpleSrvQueryData *purple_txt_resolve(const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata) |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
721 { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
722 char *query; |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
723 char *hostname; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
724 PurpleSrvQueryData *query_data; |
26827
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26672
diff
changeset
|
725 #ifndef _WIN32 |
25594
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25593
diff
changeset
|
726 PurpleSrvInternalQuery internal_query; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
727 int in[2], out[2]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
728 int pid; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
729 #else |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
730 GError* err = NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
731 static gboolean initialized = FALSE; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
732 #endif |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
733 |
27711
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
734 #ifdef USE_IDN |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
735 if (!dns_str_is_ascii(domain)) { |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
736 int ret = purple_network_convert_idn_to_ascii(domain, &hostname); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
737 if (ret != 0) { |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
738 purple_debug_error("dnssrv", "IDNA ToASCII failed\n"); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
739 cb(NULL, extradata); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
740 return NULL; |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
741 } |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
742 } else /* fallthru is intentional */ |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
743 #endif |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
744 hostname = g_strdup(domain); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
745 |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
746 query = g_strdup_printf("%s.%s", owner, hostname); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
747 purple_debug_info("dnssrv","querying TXT record for %s: %s\n", domain, |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
748 query); |
7fbf964c6c6c
Move the IDN support into the DNS routines.
Paul Aurich <paul@darkrain42.org>
parents:
27430
diff
changeset
|
749 g_free(hostname); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
750 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
751 #ifndef _WIN32 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
752 if(pipe(in) || pipe(out)) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
753 purple_debug_error("dnssrv", "Could not create pipe\n"); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
754 g_free(query); |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
755 cb(NULL, extradata); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
756 return NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
757 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
758 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
759 pid = fork(); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
760 if (pid == -1) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
761 purple_debug_error("dnssrv", "Could not create process!\n"); |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
762 cb(NULL, extradata); |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
763 g_free(query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
764 return NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
765 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
766 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
767 /* Child */ |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
768 if (pid == 0) |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
769 { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
770 g_free(query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
771 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
772 close(out[0]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
773 close(in[1]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
774 resolve(in[0], out[1]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
775 /* resolve() does not return */ |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
776 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
777 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
778 close(out[1]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
779 close(in[0]); |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
780 |
25594
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25593
diff
changeset
|
781 internal_query.type = T_TXT; |
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25593
diff
changeset
|
782 strncpy(internal_query.query, query, 255); |
27294
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
27016
diff
changeset
|
783 |
25594
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25593
diff
changeset
|
784 if (write(in[1], &internal_query, sizeof(internal_query)) < 0) |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
785 purple_debug_error("dnssrv", "Could not write to TXT resolver\n"); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
786 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
787 query_data = g_new0(PurpleSrvQueryData, 1); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
788 query_data->type = T_TXT; |
25766 | 789 query_data->cb.txt = cb; |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
790 query_data->extradata = extradata; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
791 query_data->pid = pid; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
792 query_data->fd_out = out[0]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
793 query_data->fd_in = in[1]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
794 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
795 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
796 g_free(query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
797 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
798 return query_data; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
799 #else |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
800 if (!initialized) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
801 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8"); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
802 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc( |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
803 "dnsapi.dll", "DnsRecordListFree"); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
804 initialized = TRUE; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
805 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
806 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
807 query_data = g_new0(PurpleSrvQueryData, 1); |
25766 | 808 query_data->type = DNS_TYPE_TXT; |
809 query_data->cb.txt = cb; | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
810 query_data->query = query; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
811 query_data->extradata = extradata; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
812 |
15800 | 813 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) |
814 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n"); | |
815 else { | |
816 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err); | |
817 if (query_data->resolver == NULL) { | |
25767 | 818 query_data->error_message = g_strdup_printf("TXT thread create failure: %s\n", (err && err->message) ? err->message : ""); |
15800 | 819 g_error_free(err); |
820 } | |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
821 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
822 |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
823 /* The query isn't going to happen, so finish the TXT lookup now. |
15800 | 824 * Asynchronously call the callback since stuff may not expect |
825 * the callback to be called before this returns */ | |
826 if (query_data->error_message != NULL) | |
22224
d1b36a8c920a
Change some g_idle_add(...) calls in libpurple to purple_timeout_add(0, ...)
Mark Doliner <mark@kingant.net>
parents:
22124
diff
changeset
|
827 query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
828 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
829 return query_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
830 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
831 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
832 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
833 void |
15823 | 834 purple_srv_cancel(PurpleSrvQueryData *query_data) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
835 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
836 if (query_data->handle > 0) |
15823 | 837 purple_input_remove(query_data->handle); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
838 #ifdef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
839 if (query_data->resolver != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
840 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
841 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
842 * It's not really possible to kill a thread. So instead we |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
843 * just set the callback to NULL and let the DNS lookup |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
844 * finish. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
845 */ |
25766 | 846 query_data->cb.srv = NULL; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
847 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
848 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
849 g_free(query_data->query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
850 g_free(query_data->error_message); |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
851 #else |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
852 close(query_data->fd_out); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
853 close(query_data->fd_in); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
854 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
855 g_free(query_data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
856 } |
25593
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
857 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
858 void |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
859 purple_txt_cancel(PurpleSrvQueryData *query_data) |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
860 { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
861 purple_srv_cancel(query_data); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23203
diff
changeset
|
862 } |
26672
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
863 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
864 const gchar * |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
865 purple_txt_response_get_content(PurpleTxtResponse *resp) |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
866 { |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
867 g_return_val_if_fail(resp != NULL, NULL); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
868 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
869 return resp->content; |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
870 } |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
871 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
872 void purple_txt_response_destroy(PurpleTxtResponse *resp) |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
873 { |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
874 g_return_if_fail(resp != NULL); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
875 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
876 g_free(resp->content); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
877 g_free(resp); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26671
diff
changeset
|
878 } |