Mercurial > pidgin
annotate libpurple/dnssrv.c @ 27213:3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
from Meebo.
SRV records have two fields that determine the order in which the results
should be used:
1. Priority (which we call "pref" for some reason). Records with a
lower priority will be used first.
2. Weight. Records with a higher weight are more likely to be used
first, but there is some amount of randomness. We were actually
doing this backwards and using records with lower weight first. And
we weren't randomizing. But now we are.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 29 Jun 2009 06:49:59 +0000 |
parents | 862b8208a546 |
children | e400cd35542b |
rev | line source |
---|---|
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1 /** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2 * @file dnssrv.c |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19681
diff
changeset
|
3 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19681
diff
changeset
|
4 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19681
diff
changeset
|
5 /* purple |
15373
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 |
19681
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 |
15373
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" |
15656
ca1c878be941
Include util.h to fix a warning I introduced
Evan Schoenberg <evan.s@dreskin.net>
parents:
15645
diff
changeset
|
25 #include "util.h" |
15373
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 |
23201
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> |
15373
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 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
36 #ifndef T_TXT |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
37 #define T_TXT 16 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
38 #endif |
25170 | 39 #else /* WIN32 */ |
15373
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 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
45 #ifndef DNS_TYPE_TXT |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
46 # define DNS_TYPE_TXT 16 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
47 #endif |
15373
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
50 #include "dnssrv.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
51 #include "eventloop.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
52 #include "debug.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
53 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
55 typedef union { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 HEADER hdr; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 u_char buf[1024]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 } queryans; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
59 #else |
18401
3c6bc8785af9
Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents:
16903
diff
changeset
|
60 static DNS_STATUS (WINAPI *MyDnsQuery_UTF8) ( |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
61 PCSTR lpstrName, WORD wType, DWORD fOptions, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
62 PIP4_ARRAY aipServers, PDNS_RECORD* ppQueryResultsSet, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 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:
16903
diff
changeset
|
64 static void (WINAPI *MyDnsRecordListFree) (PDNS_RECORD pRecordList, |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
65 DNS_FREE_TYPE FreeType) = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
66 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
67 |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
68 struct _PurpleTxtResponse { |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
69 char *content; |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
70 }; |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
71 |
15822 | 72 struct _PurpleSrvQueryData { |
25170 | 73 union { |
74 PurpleSrvCallback srv; | |
75 PurpleTxtCallback txt; | |
76 } cb; | |
77 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
78 gpointer extradata; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
79 guint handle; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
80 int type; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
81 #ifdef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
82 GThread *resolver; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
83 char *query; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
84 char *error_message; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
85 GSList *results; |
15712
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:
15656
diff
changeset
|
86 #else |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
87 int fd_in, fd_out; |
15712
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:
15656
diff
changeset
|
88 pid_t pid; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
89 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
90 }; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
91 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
92 typedef struct _PurpleSrvInternalQuery { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
93 int type; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
94 char query[256]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
95 } PurpleSrvInternalQuery; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
96 |
27213
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
97 typedef struct _PurpleSrvResponseContainer { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
98 PurpleSrvResponse *response; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
99 int sum; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
100 } PurpleSrvResponseContainer; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
101 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
102 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
103 * 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:
27212
diff
changeset
|
104 * 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:
27212
diff
changeset
|
105 * 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:
27212
diff
changeset
|
106 * 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:
27212
diff
changeset
|
107 */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
108 static gint |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
109 responsecompare(gconstpointer ar, gconstpointer br) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
110 { |
15822 | 111 PurpleSrvResponse *a = (PurpleSrvResponse*)ar; |
112 PurpleSrvResponse *b = (PurpleSrvResponse*)br; | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
113 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
114 if(a->pref == b->pref) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
115 if(a->weight == b->weight) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
116 return 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
117 if(a->weight < b->weight) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
118 return -1; |
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 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 if(a->pref < b->pref) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
122 return -1; |
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 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
125 |
27213
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
126 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
127 * 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:
27212
diff
changeset
|
128 * 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:
27212
diff
changeset
|
129 * (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:
27212
diff
changeset
|
130 * number selected. From RFC 2782. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
131 * |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
132 * @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:
27212
diff
changeset
|
133 * 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:
27212
diff
changeset
|
134 * @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:
27212
diff
changeset
|
135 * will be returned here. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
136 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
137 static GList *select_random_response(GList *list, |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
138 PurpleSrvResponseContainer **container_ptr) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
139 { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
140 GList *cur; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
141 size_t runningtotal; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
142 int r; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
143 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
144 runningtotal = 0; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
145 cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
146 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
147 while (cur) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
148 PurpleSrvResponseContainer *container = cur->data; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
149 runningtotal += container->response->weight; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
150 container->sum = runningtotal; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
151 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
152 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
153 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
154 /* |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
155 * 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:
27212
diff
changeset
|
156 * 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:
27212
diff
changeset
|
157 * 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:
27212
diff
changeset
|
158 * 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:
27212
diff
changeset
|
159 * 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:
27212
diff
changeset
|
160 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
161 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:
27212
diff
changeset
|
162 cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
163 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:
27212
diff
changeset
|
164 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
165 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
166 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
167 /* 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:
27212
diff
changeset
|
168 *container_ptr = cur->data; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
169 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:
27212
diff
changeset
|
170 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
171 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
172 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
173 * 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:
27212
diff
changeset
|
174 * (aka "pref"). |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
175 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
176 static void srv_reorder(GList *list, int num) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
177 { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
178 int i; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
179 GList *cur; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
180 GList *container_list = NULL; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
181 PurpleSrvResponseContainer *container; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
182 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
183 if (num < 2) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
184 /* Nothing to sort */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
185 return; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
186 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
187 /* 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:
27212
diff
changeset
|
188 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:
27212
diff
changeset
|
189 container = g_new(PurpleSrvResponseContainer, 1); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
190 container->response = cur->data; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
191 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:
27212
diff
changeset
|
192 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
193 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:
27212
diff
changeset
|
194 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
195 /* |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
196 * 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:
27212
diff
changeset
|
197 * 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:
27212
diff
changeset
|
198 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
199 cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
200 while (container_list) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
201 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:
27212
diff
changeset
|
202 cur->data = container->response; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
203 g_free(container); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
204 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
205 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
206 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
207 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
208 /** |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
209 * Sorts a GList of PurpleSrvResponse's according to the |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
210 * algorithm described in RFC 2782. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
211 * |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
212 * @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:
27212
diff
changeset
|
213 * @param The original list, resorted |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
214 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
215 static GList *purple_srv_sort(GList *list) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
216 { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
217 GList *cur, *start; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
218 int count; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
219 int pref; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
220 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
221 if (!list || !list->next) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
222 /* Nothing to sort */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
223 return list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
224 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
225 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:
27212
diff
changeset
|
226 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
227 start = cur = list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
228 count = 1; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
229 while (cur) { |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
230 PurpleSrvResponse *next_response; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
231 pref = ((PurpleSrvResponse *)cur->data)->pref; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
232 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:
27212
diff
changeset
|
233 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:
27212
diff
changeset
|
234 /* |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
235 * 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:
27212
diff
changeset
|
236 * priority. Sort them by weight. |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
237 */ |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
238 srv_reorder(start, count); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
239 start = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
240 count = 0; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
241 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
242 count++; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
243 cur = cur->next; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
244 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
245 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
246 return list; |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
247 } |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
248 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
249 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
250 |
16634
c028fc690b5d
Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents:
15828
diff
changeset
|
251 G_GNUC_NORETURN static void |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
252 resolve(int in, int out) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
253 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
254 GList *ret = NULL; |
15822 | 255 PurpleSrvResponse *srvres; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
256 PurpleTxtResponse *txtres; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
257 queryans answer; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
258 int size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
259 int qdcount; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
260 int ancount; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
261 guchar *end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
262 guchar *cp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
263 gchar name[256]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
264 guint16 type, dlen, pref, weight, port; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
265 PurpleSrvInternalQuery query; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
266 |
15645
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:
15373
diff
changeset
|
267 #ifdef HAVE_SIGNAL_H |
15822 | 268 purple_restore_default_signal_handlers(); |
15645
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:
15373
diff
changeset
|
269 #endif |
15799 | 270 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
271 if (read(in, &query, sizeof(query)) <= 0) { |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
272 close(out); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
273 close(in); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
274 _exit(0); |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
275 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
276 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
277 size = res_query( query.query, C_IN, query.type, (u_char*)&answer, sizeof( answer)); |
26934
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
278 if (size == -1) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
279 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:
26747
diff
changeset
|
280 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:
26747
diff
changeset
|
281 close(out); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
282 close(in); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
283 _exit(0); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
284 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
285 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
286 qdcount = ntohs(answer.hdr.qdcount); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
287 ancount = ntohs(answer.hdr.ancount); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
288 cp = (guchar*)&answer + sizeof(HEADER); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
289 end = (guchar*)&answer + size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
290 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
291 /* skip over unwanted stuff */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
292 while (qdcount-- > 0 && cp < end) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
293 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
|
294 if(size < 0) goto end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
295 cp += size + QFIXEDSZ; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
296 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
297 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
298 while (ancount-- > 0 && cp < end) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
299 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
|
300 if(size < 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
301 goto end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
302 cp += size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
303 GETSHORT(type,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
304 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
305 /* 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
|
306 cp += 6; |
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 GETSHORT(dlen,cp); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
309 if (query.type == T_SRV) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
310 GETSHORT(pref,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
311 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
312 GETSHORT(weight,cp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
313 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
314 GETSHORT(port,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 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
|
317 if(size < 0 ) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
318 goto end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
319 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
320 cp += size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
321 |
15822 | 322 srvres = g_new0(PurpleSrvResponse, 1); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
323 strcpy(srvres->hostname, name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
324 srvres->pref = pref; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
325 srvres->port = port; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
326 srvres->weight = weight; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
327 |
27213
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
328 ret = g_list_prepend(ret, srvres); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
329 } else if (query.type == T_TXT) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
330 txtres = g_new0(PurpleTxtResponse, 1); |
26589
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
331 txtres->content = g_strndup((gchar*)(++cp), dlen-1); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
332 ret = g_list_append(ret, txtres); |
25037
94c8bef52c66
* some further bugfixing, BIND's libresolv does so much for the programmer, just happy it exists
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25036
diff
changeset
|
333 cp += dlen - 1; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
334 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
335 cp += dlen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
336 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
337 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
338 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
339 end: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
340 size = g_list_length(ret); |
27213
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
341 |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
342 if (query.type == T_SRV) |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
343 ret = purple_srv_sort(ret); |
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
344 |
26189 | 345 /* TODO: Check return value */ |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
346 write(out, &(query.type), sizeof(query.type)); |
25036
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25035
diff
changeset
|
347 write(out, &size, sizeof(size)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
348 while (ret != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
349 { |
26189 | 350 /* TODO: Check return value */ |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
351 if (query.type == T_SRV) write(out, ret->data, sizeof(PurpleSrvResponse)); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
352 if (query.type == T_TXT) write(out, ret->data, sizeof(PurpleTxtResponse)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
353 g_free(ret->data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
354 ret = g_list_remove(ret, ret->data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
355 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
356 |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
357 close(out); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
358 close(in); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
359 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
360 _exit(0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
361 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
362 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
363 static void |
15822 | 364 resolved(gpointer data, gint source, PurpleInputCondition cond) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
365 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
366 int size; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
367 int type; |
15822 | 368 PurpleSrvQueryData *query_data = (PurpleSrvQueryData*)data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
369 int i; |
15712
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:
15656
diff
changeset
|
370 int status; |
26934
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
371 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
372 if (read(source, &type, sizeof(type)) == sizeof(type)) { |
26934
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
373 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:
26747
diff
changeset
|
374 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:
26747
diff
changeset
|
375 if (size == -1) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
376 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:
26747
diff
changeset
|
377 /* 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:
26747
diff
changeset
|
378 res_init(); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
379 } else |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
380 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:
26747
diff
changeset
|
381 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
382 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:
26747
diff
changeset
|
383 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:
26747
diff
changeset
|
384 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:
26747
diff
changeset
|
385 } 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:
26747
diff
changeset
|
386 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:
26747
diff
changeset
|
387 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:
26747
diff
changeset
|
388 } else { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
389 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:
26747
diff
changeset
|
390 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
391 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
392 } else if (size) { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
393 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:
26747
diff
changeset
|
394 PurpleSrvResponse *res; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
395 PurpleSrvResponse *tmp; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
396 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:
26747
diff
changeset
|
397 ssize_t red; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
398 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:
26747
diff
changeset
|
399 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:
26747
diff
changeset
|
400 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:
26747
diff
changeset
|
401 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:
26747
diff
changeset
|
402 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:
26747
diff
changeset
|
403 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:
26747
diff
changeset
|
404 "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:
26747
diff
changeset
|
405 size = 0; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
406 g_free(res); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
407 res = NULL; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
408 } |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
409 } |
26934
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
410 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
411 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:
26747
diff
changeset
|
412 } 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:
26747
diff
changeset
|
413 GSList *responses = NULL; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
414 PurpleTxtResponse *res; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
415 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:
26747
diff
changeset
|
416 ssize_t red; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
417 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:
26747
diff
changeset
|
418 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:
26747
diff
changeset
|
419 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:
26747
diff
changeset
|
420 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:
26747
diff
changeset
|
421 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:
26747
diff
changeset
|
422 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:
26747
diff
changeset
|
423 "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:
26747
diff
changeset
|
424 size = 0; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
425 g_free(res); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
426 g_slist_foreach(responses, (GFunc)purple_txt_response_destroy, NULL); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
427 g_slist_free(responses); |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
428 responses = NULL; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
429 break; |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
430 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
431 } |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
432 |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
433 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:
26747
diff
changeset
|
434 } else { |
c162a088489f
Call res_init() when DNS queries fail in case the failure indicates a timeout
Paul Aurich <paul@darkrain42.org>
parents:
26747
diff
changeset
|
435 purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
436 } |
22107
bfe1854bbf87
More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents:
20636
diff
changeset
|
437 } |
16903
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:
16634
diff
changeset
|
438 } |
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:
16634
diff
changeset
|
439 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
440 |
15712
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:
15656
diff
changeset
|
441 waitpid(query_data->pid, &status, 0); |
15822 | 442 purple_srv_cancel(query_data); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
443 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
444 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
445 #else /* _WIN32 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
446 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
447 /** 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
|
448 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
449 static gboolean |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
450 res_main_thread_cb(gpointer data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
451 { |
15822 | 452 PurpleSrvResponse *srvres = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
453 int size = 0; |
15822 | 454 PurpleSrvQueryData *query_data = data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
455 if(query_data->error_message != NULL) |
15822 | 456 purple_debug_error("dnssrv", query_data->error_message); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
457 else { |
26745
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26590
diff
changeset
|
458 if (query_data->type == DNS_TYPE_SRV) { |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
459 PurpleSrvResponse *srvres_tmp = NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
460 GSList *lst = query_data->results; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
461 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
462 size = g_slist_length(lst); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
463 |
25170 | 464 if(query_data->cb.srv && size > 0) |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
465 srvres_tmp = srvres = g_new0(PurpleSrvResponse, size); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
466 while (lst) { |
25170 | 467 if(query_data->cb.srv) |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
468 memcpy(srvres_tmp++, lst->data, sizeof(PurpleSrvResponse)); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
469 g_free(lst->data); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
470 lst = g_slist_remove(lst, lst->data); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
471 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
472 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
473 query_data->results = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
474 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
475 purple_debug_info("dnssrv", "found %d SRV entries\n", size); |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
476 |
25170 | 477 if(query_data->cb.srv) query_data->cb.srv(srvres, size, query_data->extradata); |
26745
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26590
diff
changeset
|
478 } else if (query_data->type == DNS_TYPE_TXT) { |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
479 GSList *lst = query_data->results; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
480 |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
481 purple_debug_info("dnssrv", "found %d TXT entries\n", g_slist_length(lst)); |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
482 |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
483 if (query_data->cb.txt) { |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
484 query_data->results = NULL; |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
485 query_data->cb.txt(lst, query_data->extradata); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
486 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
487 } else { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
488 purple_debug_error("dnssrv", "unknown query type"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
489 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
490 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
491 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
492 query_data->resolver = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
493 query_data->handle = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
494 |
15822 | 495 purple_srv_cancel(query_data); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
496 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
497 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
498 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
499 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
500 static gpointer |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
501 res_thread(gpointer data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
502 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
503 PDNS_RECORD dr = NULL; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
504 int type; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
505 DNS_STATUS ds; |
15822 | 506 PurpleSrvQueryData *query_data = data; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
507 type = query_data->type; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
508 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
|
509 if (ds != ERROR_SUCCESS) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
510 gchar *msg = g_win32_error_message(ds); |
25170 | 511 if (type == DNS_TYPE_SRV) { |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
512 query_data->error_message = g_strdup_printf("Couldn't look up SRV record. %s (%lu).\n", msg, ds); |
25170 | 513 } else if (type == DNS_TYPE_TXT) { |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
514 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:
23201
diff
changeset
|
515 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
516 g_free(msg); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
517 } else { |
25170 | 518 if (type == DNS_TYPE_SRV) { |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
519 PDNS_RECORD dr_tmp; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
520 GSList *lst = NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
521 DNS_SRV_DATA *srv_data; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
522 PurpleSrvResponse *srvres; |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
523 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
524 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:
23201
diff
changeset
|
525 /* 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:
23201
diff
changeset
|
526 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:
23201
diff
changeset
|
527 continue; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
528 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
529 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
530 srv_data = &dr_tmp->Data.SRV; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
531 srvres = g_new0(PurpleSrvResponse, 1); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
532 strncpy(srvres->hostname, srv_data->pNameTarget, 255); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
533 srvres->hostname[255] = '\0'; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
534 srvres->pref = srv_data->wPriority; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
535 srvres->port = srv_data->wPort; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
536 srvres->weight = srv_data->wWeight; |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
537 |
27213
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
538 lst = g_slist_prepend(lst, srvres); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
539 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
540 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
541 MyDnsRecordListFree(dr, DnsFreeRecordList); |
27213
3e516701dd33
Changes to our DNS SRV record sorting, care of Vijay Vijay Raghunathan
Mark Doliner <mark@kingant.net>
parents:
27212
diff
changeset
|
542 query_data->results = purple_srv_sort(lst); |
26747
7b0231e5c818
Missed one (copying changes manually between computers is clearly an error-ful
Paul Aurich <paul@darkrain42.org>
parents:
26745
diff
changeset
|
543 } else if (type == DNS_TYPE_TXT) { |
26589
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
544 PDNS_RECORD dr_tmp; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
545 GSList *lst = NULL; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
546 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:
26270
diff
changeset
|
547 PurpleTxtResponse *txtres; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
548 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
549 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:
26270
diff
changeset
|
550 GString *s; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
551 int i; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
552 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
553 /* 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:
26270
diff
changeset
|
554 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:
26270
diff
changeset
|
555 continue; |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
556 } |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
557 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
558 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:
26270
diff
changeset
|
559 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:
26270
diff
changeset
|
560 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
561 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:
26270
diff
changeset
|
562 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:
26270
diff
changeset
|
563 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:
26270
diff
changeset
|
564 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:
26270
diff
changeset
|
565 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
566 lst = g_slist_append(lst, txtres); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
567 } |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
568 |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
569 MyDnsRecordListFree(dr, DnsFreeRecordList); |
400f74b95c0e
First crack at Win32 TXT DNS query code and don't leak the PurpleTxtResponses
Paul Aurich <paul@darkrain42.org>
parents:
26270
diff
changeset
|
570 query_data->results = lst; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
571 } else { |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
572 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
573 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
574 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
575 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
576 /* back to main thread */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
577 /* 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
|
578 purple_timeout_add(0, res_main_thread_cb, query_data); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
579 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
580 g_thread_exit(NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
581 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
582 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
583 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
584 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
585 |
15822 | 586 PurpleSrvQueryData * |
587 purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata) | |
15373
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 char *query; |
15822 | 590 PurpleSrvQueryData *query_data; |
26745
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26590
diff
changeset
|
591 #ifndef _WIN32 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
592 PurpleSrvInternalQuery internal_query; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
593 int in[2], out[2]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
594 int pid; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
595 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
596 GError* err = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
597 static gboolean initialized = FALSE; |
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 |
24747
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24451
diff
changeset
|
600 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:
24451
diff
changeset
|
601 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:
24451
diff
changeset
|
602 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:
24451
diff
changeset
|
603 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:
24451
diff
changeset
|
604 } |
d1da5c4c1e6b
Fix a crash in DNS SRV resolution when one of the required parameters is NULL.
Florian Quèze <florian@instantbird.org>
parents:
24451
diff
changeset
|
605 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
606 query = g_strdup_printf("_%s._%s.%s", protocol, transport, domain); |
15822 | 607 purple_debug_info("dnssrv","querying SRV record for %s\n", query); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
608 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
609 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
610 if(pipe(in) || pipe(out)) { |
15822 | 611 purple_debug_error("dnssrv", "Could not create pipe\n"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
612 g_free(query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
613 cb(NULL, 0, extradata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
614 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
615 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
616 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
617 pid = fork(); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
618 if (pid == -1) { |
15822 | 619 purple_debug_error("dnssrv", "Could not create process!\n"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
620 cb(NULL, 0, extradata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
621 g_free(query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
622 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
623 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
624 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
625 /* Child */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
626 if (pid == 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
627 { |
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
|
628 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
|
629 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
630 close(out[0]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
631 close(in[1]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
632 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
|
633 /* resolve() does not return */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
634 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
635 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
636 close(out[1]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
637 close(in[0]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
638 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
639 internal_query.type = T_SRV; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
640 strncpy(internal_query.query, query, 255); |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
641 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
642 if (write(in[1], &internal_query, sizeof(internal_query)) < 0) |
15822 | 643 purple_debug_error("dnssrv", "Could not write to SRV resolver\n"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
644 |
15822 | 645 query_data = g_new0(PurpleSrvQueryData, 1); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
646 query_data->type = T_SRV; |
25170 | 647 query_data->cb.srv = cb; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
648 query_data->extradata = extradata; |
15712
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:
15656
diff
changeset
|
649 query_data->pid = pid; |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
650 query_data->fd_out = out[0]; |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
651 query_data->fd_in = in[1]; |
15822 | 652 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data); |
15373
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 g_free(query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
655 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
656 return query_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
657 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
658 if (!initialized) { |
15822 | 659 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8"); |
660 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc( | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
661 "dnsapi.dll", "DnsRecordListFree"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
662 initialized = TRUE; |
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 |
15822 | 665 query_data = g_new0(PurpleSrvQueryData, 1); |
25170 | 666 query_data->type = DNS_TYPE_SRV; |
667 query_data->cb.srv = cb; | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
668 query_data->query = query; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
669 query_data->extradata = extradata; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
670 |
15799 | 671 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) |
672 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n"); | |
673 else { | |
674 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err); | |
675 if (query_data->resolver == NULL) { | |
676 query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", (err && err->message) ? err->message : ""); | |
677 g_error_free(err); | |
678 } | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
679 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
680 |
15799 | 681 /* The query isn't going to happen, so finish the SRV lookup now. |
682 * Asynchronously call the callback since stuff may not expect | |
683 * the callback to be called before this returns */ | |
684 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
|
685 query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
686 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
687 return query_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
688 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
689 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
690 |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
691 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:
23201
diff
changeset
|
692 { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
693 char *query; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
694 PurpleSrvQueryData *query_data; |
26745
e5c874075b42
Build error/warning fixes. Still not tested because libxmpp.dll won't load.
Paul Aurich <paul@darkrain42.org>
parents:
26590
diff
changeset
|
695 #ifndef _WIN32 |
25036
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25035
diff
changeset
|
696 PurpleSrvInternalQuery internal_query; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
697 int in[2], out[2]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
698 int pid; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
699 #else |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
700 GError* err = NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
701 static gboolean initialized = FALSE; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
702 #endif |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
703 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
704 query = g_strdup_printf("%s.%s", owner, domain); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
705 purple_debug_info("dnssrv","querying TXT record for %s\n", query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
706 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
707 #ifndef _WIN32 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
708 if(pipe(in) || pipe(out)) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
709 purple_debug_error("dnssrv", "Could not create pipe\n"); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
710 g_free(query); |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
711 cb(NULL, extradata); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
712 return NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
713 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
714 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
715 pid = fork(); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
716 if (pid == -1) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
717 purple_debug_error("dnssrv", "Could not create process!\n"); |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
718 cb(NULL, extradata); |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
719 g_free(query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
720 return NULL; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
721 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
722 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
723 /* Child */ |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
724 if (pid == 0) |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
725 { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
726 g_free(query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
727 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
728 close(out[0]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
729 close(in[1]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
730 resolve(in[0], out[1]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
731 /* resolve() does not return */ |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
732 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
733 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
734 close(out[1]); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
735 close(in[0]); |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
736 |
25036
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25035
diff
changeset
|
737 internal_query.type = T_TXT; |
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25035
diff
changeset
|
738 strncpy(internal_query.query, query, 255); |
27212
862b8208a546
Strip trailing whitespace and spaces to tab
Mark Doliner <mark@kingant.net>
parents:
26934
diff
changeset
|
739 |
25036
3c3480683075
* fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25035
diff
changeset
|
740 if (write(in[1], &internal_query, sizeof(internal_query)) < 0) |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
741 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:
23201
diff
changeset
|
742 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
743 query_data = g_new0(PurpleSrvQueryData, 1); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
744 query_data->type = T_TXT; |
25170 | 745 query_data->cb.txt = cb; |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
746 query_data->extradata = extradata; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
747 query_data->pid = pid; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
748 query_data->fd_out = out[0]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
749 query_data->fd_in = in[1]; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
750 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:
23201
diff
changeset
|
751 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
752 g_free(query); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
753 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
754 return query_data; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
755 #else |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
756 if (!initialized) { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
757 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:
23201
diff
changeset
|
758 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc( |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
759 "dnsapi.dll", "DnsRecordListFree"); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
760 initialized = TRUE; |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
761 } |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
762 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
763 query_data = g_new0(PurpleSrvQueryData, 1); |
25170 | 764 query_data->type = DNS_TYPE_TXT; |
765 query_data->cb.txt = cb; | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
766 query_data->query = query; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
767 query_data->extradata = extradata; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
768 |
15799 | 769 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) |
770 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n"); | |
771 else { | |
772 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err); | |
773 if (query_data->resolver == NULL) { | |
25171 | 774 query_data->error_message = g_strdup_printf("TXT thread create failure: %s\n", (err && err->message) ? err->message : ""); |
15799 | 775 g_error_free(err); |
776 } | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
777 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
778 |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
779 /* The query isn't going to happen, so finish the TXT lookup now. |
15799 | 780 * Asynchronously call the callback since stuff may not expect |
781 * the callback to be called before this returns */ | |
782 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
|
783 query_data->handle = purple_timeout_add(0, res_main_thread_cb, query_data); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
784 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
785 return query_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
786 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
787 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
788 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
789 void |
15822 | 790 purple_srv_cancel(PurpleSrvQueryData *query_data) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
791 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
792 if (query_data->handle > 0) |
15822 | 793 purple_input_remove(query_data->handle); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
794 #ifdef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
795 if (query_data->resolver != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
796 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
797 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
798 * 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
|
799 * 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
|
800 * finish. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
801 */ |
25170 | 802 query_data->cb.srv = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
803 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
804 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
805 g_free(query_data->query); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
806 g_free(query_data->error_message); |
20232
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
807 #else |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
808 close(query_data->fd_out); |
b7c0c79585f9
applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents:
19681
diff
changeset
|
809 close(query_data->fd_in); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
810 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
811 g_free(query_data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
812 } |
25035
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
813 |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
814 void |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
815 purple_txt_cancel(PurpleSrvQueryData *query_data) |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
816 { |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
817 purple_srv_cancel(query_data); |
affaa4c4836e
* some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23201
diff
changeset
|
818 } |
26590
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
819 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
820 const gchar * |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
821 purple_txt_response_get_content(PurpleTxtResponse *resp) |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
822 { |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
823 g_return_val_if_fail(resp != NULL, NULL); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
824 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
825 return resp->content; |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
826 } |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
827 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
828 void purple_txt_response_destroy(PurpleTxtResponse *resp) |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
829 { |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
830 g_return_if_fail(resp != NULL); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
831 |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
832 g_free(resp->content); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
833 g_free(resp); |
acee7d2b1983
Hide PurpleTxtResponse and use a more purple API
Paul Aurich <paul@darkrain42.org>
parents:
26589
diff
changeset
|
834 } |