annotate libpurple/dnssrv.c @ 26488:061df5754d20

Fix up the propagate
author Paul Aurich <paul@darkrain42.org>
date Sun, 05 Apr 2009 21:18:15 +0000
parents e4a060a1e3de
children 400f74b95c0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file 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
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
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
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
68 struct _PurpleSrvQueryData {
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
69 union {
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
70 PurpleSrvCallback srv;
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
71 PurpleTxtCallback txt;
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
72 } cb;
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
73
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 gpointer extradata;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 guint handle;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
76 int type;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 GThread *resolver;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 char *query;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 char *error_message;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 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
82 #else
20232
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
83 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
84 pid_t pid;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
88 typedef struct _PurpleSrvInternalQuery {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
89 int type;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
90 char query[256];
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
91 } PurpleSrvInternalQuery;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
92
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 static gint
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 responsecompare(gconstpointer ar, gconstpointer br)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
96 PurpleSrvResponse *a = (PurpleSrvResponse*)ar;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
97 PurpleSrvResponse *b = (PurpleSrvResponse*)br;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 if(a->pref == b->pref) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 if(a->weight == b->weight)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 if(a->weight < b->weight)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 return 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 if(a->pref < b->pref)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 return 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112
16634
c028fc690b5d Mark two functions as "noreturn"
Mark Doliner <mark@kingant.net>
parents: 15828
diff changeset
113 G_GNUC_NORETURN static void
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 resolve(int in, int out)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 GList *ret = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
117 PurpleSrvResponse *srvres;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
118 PurpleTxtResponse *txtres;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 queryans answer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 int size;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 int qdcount;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 int ancount;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 guchar *end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 guchar *cp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 gchar name[256];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 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
127 PurpleSrvInternalQuery query;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128
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
129 #ifdef HAVE_SIGNAL_H
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
130 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
131 #endif
15799
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
132
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
133 if (read(in, &query, sizeof(query)) <= 0) {
20232
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
134 close(out);
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
135 close(in);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 _exit(0);
20232
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
137 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
139 size = res_query( query.query, C_IN, query.type, (u_char*)&answer, sizeof( answer));
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
140
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 qdcount = ntohs(answer.hdr.qdcount);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 ancount = ntohs(answer.hdr.ancount);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 cp = (guchar*)&answer + sizeof(HEADER);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 end = (guchar*)&answer + size;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 /* skip over unwanted stuff */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 while (qdcount-- > 0 && cp < end) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 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
149 if(size < 0) goto end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 cp += size + QFIXEDSZ;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 while (ancount-- > 0 && cp < end) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 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
155 if(size < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 goto end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 cp += size;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 GETSHORT(type,cp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 /* 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
161 cp += 6;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 GETSHORT(dlen,cp);
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
164 if (query.type == T_SRV) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 GETSHORT(pref,cp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 GETSHORT(weight,cp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 GETSHORT(port,cp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 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
172 if(size < 0 )
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 goto end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 cp += size;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
177 srvres = g_new0(PurpleSrvResponse, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 strcpy(srvres->hostname, name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 srvres->pref = pref;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 srvres->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 srvres->weight = weight;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 ret = g_list_insert_sorted(ret, srvres, responsecompare);
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
184 } else if (query.type == T_TXT) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
185 txtres = g_new0(PurpleTxtResponse, 1);
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
186 strncpy(txtres->content, (gchar*)(++cp), dlen-1);
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
187 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
188 cp += dlen - 1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 cp += dlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 end:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 size = g_list_length(ret);
26189
a155920a6f66 Just a note
Mark Doliner <mark@kingant.net>
parents: 24747
diff changeset
196 /* TODO: Check return value */
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
197 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
198 write(out, &size, sizeof(size));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 while (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 {
26189
a155920a6f66 Just a note
Mark Doliner <mark@kingant.net>
parents: 24747
diff changeset
201 /* TODO: Check return value */
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
202 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
203 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
204 g_free(ret->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 ret = g_list_remove(ret, ret->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207
20232
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
208 close(out);
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
209 close(in);
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
210
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 _exit(0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
215 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
216 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 int size;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
218 int type;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
219 PurpleSrvQueryData *query_data = (PurpleSrvQueryData*)data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 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
221 int status;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
222
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
223 if (read(source, &type, sizeof(type)) == sizeof(type)) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
224 if (type == T_SRV) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
225 PurpleSrvResponse *res;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
226 PurpleSrvResponse *tmp;
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
227 PurpleSrvCallback cb = query_data->cb.srv;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
228 if (read(source, &size, sizeof(int)) == sizeof(int)) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
229 ssize_t red;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
230 purple_debug_info("dnssrv","found %d SRV entries\n", size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
231 tmp = res = g_new0(PurpleSrvResponse, size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
232 for (i = 0; i < size; i++) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
233 red = read(source, tmp++, sizeof(PurpleSrvResponse));
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
234 if (red != sizeof(PurpleSrvResponse)) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
235 purple_debug_error("dnssrv","unable to read srv "
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
236 "response: %s\n", g_strerror(errno));
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
237 size = 0;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
238 g_free(res);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
239 res = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
240 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
241 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
242 } else {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
243 purple_debug_info("dnssrv","found 0 SRV entries; errno is %i\n", errno);
22107
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 20636
diff changeset
244 size = 0;
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 20636
diff changeset
245 res = NULL;
bfe1854bbf87 More compiler warning fixes from o_sukhodolsky (with additions by me).
Mark Doliner <mark@kingant.net>
parents: 20636
diff changeset
246 }
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
247 cb(res, size, query_data->extradata);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
248 } else if (type == T_TXT) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
249 PurpleTxtResponse *res;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
250 PurpleTxtResponse *tmp;
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
251 PurpleTxtCallback cb = query_data->cb.txt;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
252 if (read(source, &size, sizeof(int)) == sizeof(int)) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
253 ssize_t red;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
254 purple_debug_info("dnssrv","found %d TXT entries\n", size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
255 tmp = res = g_new0(PurpleTxtResponse, size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
256 for (i = 0; i < size; i++) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
257 red = read(source, tmp++, sizeof(PurpleTxtResponse));
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
258 if (red != sizeof(PurpleTxtResponse)) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
259 purple_debug_error("dnssrv","unable to read txt "
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
260 "response: %s\n", g_strerror(errno));
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
261 size = 0;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
262 g_free(res);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
263 res = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
264 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
265 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
266 } else {
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
267 purple_debug_info("dnssrv","found 0 TXT entries; errno is %i\n", errno);
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
268 size = 0;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
269 res = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
270 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
271 cb(res, size, query_data->extradata);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
272 } else {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
273 purple_debug_info("dnssrv","type unknown of DNS result entry; errno is %i\n", errno);
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
274 }
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
275 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276
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
277 waitpid(query_data->pid, &status, 0);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
278 purple_srv_cancel(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 #else /* _WIN32 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 /** 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
284
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 res_main_thread_cb(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
288 PurpleSrvResponse *srvres = NULL;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
289 PurpleTxtResponse *txtres = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 int size = 0;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
291 PurpleSrvQueryData *query_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 if(query_data->error_message != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
293 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
294 else {
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
295 if (query_data->type == T_SRV) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
296 PurpleSrvResponse *srvres_tmp = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
297 GSList *lst = query_data->results;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
298
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
299 size = g_slist_length(lst);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
301 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
302 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
303 while (lst) {
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
304 if(query_data->cb.srv)
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
305 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
306 g_free(lst->data);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
307 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
308 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
309
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
310 query_data->results = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
312 purple_debug_info("dnssrv", "found %d SRV entries\n", size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
313
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
314 if(query_data->cb.srv) query_data->cb.srv(srvres, size, query_data->extradata);
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
315 } else if (query_data->type == T_TXT) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
316 PurpleTxtResponse *txtres_tmp = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
317 GSList *lst = query_data->results;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
318
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
319 size = g_slist_length(lst);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
320
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
321 if(query_data->cb.txt && size > 0)
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
322 txtres_tmp = txtres = g_new0(PurpleTxtResponse, size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
323 while (lst) {
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
324 if(query_data->cb.txt)
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
325 memcpy(txtres_tmp++, lst->data, sizeof(PurpleTxtResponse));
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
326 g_free(lst->data);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
327 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
328 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
329
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
330 query_data->results = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
331
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
332 purple_debug_info("dnssrv", "found %d TXT entries\n", size);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
333
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
334 if(query_data->cb.txt) query_data->cb.txt(txtres, size, query_data->extradata);
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
335 } else {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
336 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
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 query_data->resolver = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 query_data->handle = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
343 purple_srv_cancel(query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 static gpointer
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 res_thread(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 PDNS_RECORD dr = NULL;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
352 int type;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 DNS_STATUS ds;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
354 PurpleSrvQueryData *query_data = data;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
355 type = query_data->type;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 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
357 if (ds != ERROR_SUCCESS) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 gchar *msg = g_win32_error_message(ds);
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
359 if (type == DNS_TYPE_SRV) {
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
360 query_data->error_message = g_strdup_printf("Couldn't look up SRV record. %s (%lu).\n", msg, ds);
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
361 } 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
362 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
363 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 g_free(msg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 } else {
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
366 if (type == DNS_TYPE_SRV) {
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
367 PDNS_RECORD dr_tmp;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
368 GSList *lst = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
369 DNS_SRV_DATA *srv_data;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
370 PurpleSrvResponse *srvres;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
371
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
372 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
373 /* 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
374 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
375 continue;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
376 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
378 srv_data = &dr_tmp->Data.SRV;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
379 srvres = g_new0(PurpleSrvResponse, 1);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
380 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
381 srvres->hostname[255] = '\0';
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
382 srvres->pref = srv_data->wPriority;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
383 srvres->port = srv_data->wPort;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
384 srvres->weight = srv_data->wWeight;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
385
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
386 lst = g_slist_insert_sorted(lst, srvres, responsecompare);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
389 MyDnsRecordListFree(dr, DnsFreeRecordList);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
390 query_data->results = lst;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
391 } else if (type == T_TXT) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
392 #error IMPLEMENTATION MISSING
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
393 } else {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
394
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 /* back to main thread */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 /* 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
400 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
401
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 g_thread_exit(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
408 PurpleSrvQueryData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
409 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
410 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 char *query;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
412 PurpleSrvQueryData *query_data;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
413 PurpleSrvInternalQuery internal_query;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 int in[2], out[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 int pid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 GError* err = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 static gboolean initialized = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421
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
422 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
423 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
424 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
425 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
426 }
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
427
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 query = g_strdup_printf("_%s._%s.%s", protocol, transport, domain);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
429 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
430
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 if(pipe(in) || pipe(out)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
433 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
434 g_free(query);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 cb(NULL, 0, extradata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 pid = fork();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440 if (pid == -1) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
441 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
442 cb(NULL, 0, extradata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 g_free(query);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 }
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 /* Child */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 if (pid == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 {
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
450 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
451
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 close(out[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 close(in[1]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 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
455 /* resolve() does not return */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 close(out[1]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459 close(in[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
461 internal_query.type = T_SRV;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
462 strncpy(internal_query.query, query, 255);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
463
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
464 if (write(in[1], &internal_query, sizeof(internal_query)) < 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
465 purple_debug_error("dnssrv", "Could not write to SRV resolver\n");
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
466
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
468 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
469 query_data->type = T_SRV;
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
470 query_data->cb.srv = cb;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 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
472 query_data->pid = pid;
20232
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
473 query_data->fd_out = out[0];
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
474 query_data->fd_in = in[1];
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
475 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
476
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 g_free(query);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 return query_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 if (!initialized) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
482 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
483 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc(
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 "dnsapi.dll", "DnsRecordListFree");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 initialized = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
488 query_data = g_new0(PurpleSrvQueryData, 1);
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
489 query_data->type = DNS_TYPE_SRV;
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
490 query_data->cb.srv = cb;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 query_data->query = query;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 query_data->extradata = extradata;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493
15799
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
494 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree)
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
495 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n");
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
496 else {
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
497 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err);
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
498 if (query_data->resolver == NULL) {
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
499 query_data->error_message = g_strdup_printf("SRV thread create failure: %s\n", (err && err->message) ? err->message : "");
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
500 g_error_free(err);
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
501 }
15373
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
15799
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
504 /* The query isn't going to happen, so finish the SRV lookup now.
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
505 * Asynchronously call the callback since stuff may not expect
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
506 * the callback to be called before this returns */
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
507 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
508 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
509
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 return query_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
514 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
515 {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
516 char *query;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
517 PurpleSrvQueryData *query_data;
25036
3c3480683075 * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25035
diff changeset
518 PurpleSrvInternalQuery internal_query;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
519 #ifndef _WIN32
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
520 int in[2], out[2];
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
521 int pid;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
522 #else
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
523 GError* err = NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
524 static gboolean initialized = FALSE;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
525 #endif
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
526
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
527 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
528 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
529
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
530 #ifndef _WIN32
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
531 if(pipe(in) || pipe(out)) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
532 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
533 g_free(query);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
534 cb(NULL, 0, extradata);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
535 return NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
536 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
537
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
538 pid = fork();
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
539 if (pid == -1) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
540 purple_debug_error("dnssrv", "Could not create process!\n");
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
541 cb(NULL, 0, extradata);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
542 g_free(query);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
543 return NULL;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
544 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
545
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
546 /* Child */
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
547 if (pid == 0)
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
548 {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
549 g_free(query);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
550
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
551 close(out[0]);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
552 close(in[1]);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
553 resolve(in[0], out[1]);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
554 /* resolve() does not return */
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
555 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
556
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
557 close(out[1]);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
558 close(in[0]);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
559
25036
3c3480683075 * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25035
diff changeset
560 internal_query.type = T_TXT;
3c3480683075 * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25035
diff changeset
561 strncpy(internal_query.query, query, 255);
3c3480683075 * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25035
diff changeset
562
3c3480683075 * fixing some bugs, finishing support for TXT queries
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25035
diff changeset
563 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
564 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
565
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
566 query_data = g_new0(PurpleSrvQueryData, 1);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
567 query_data->type = T_TXT;
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
568 query_data->cb.txt = cb;
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
569 query_data->extradata = extradata;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
570 query_data->pid = pid;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
571 query_data->fd_out = out[0];
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
572 query_data->fd_in = in[1];
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
573 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
574
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
575 g_free(query);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
576
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
577 return query_data;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
578 #else
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
579 if (!initialized) {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
580 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
581 MyDnsRecordListFree = (void*) wpurple_find_and_loadproc(
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
582 "dnsapi.dll", "DnsRecordListFree");
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
583 initialized = TRUE;
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
584 }
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
585
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
586 query_data = g_new0(PurpleSrvQueryData, 1);
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
587 query_data->type = DNS_TYPE_TXT;
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
588 query_data->cb.txt = cb;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 query_data->query = query;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590 query_data->extradata = extradata;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591
15799
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
592 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree)
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
593 query_data->error_message = g_strdup("System missing DNS API (Requires W2K+)\n");
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
594 else {
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
595 query_data->resolver = g_thread_create(res_thread, query_data, FALSE, &err);
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
596 if (query_data->resolver == NULL) {
25171
816c096d1ea8 Cut-n-paste typo
Paul Aurich <paul@darkrain42.org>
parents: 25170
diff changeset
597 query_data->error_message = g_strdup_printf("TXT thread create failure: %s\n", (err && err->message) ? err->message : "");
15799
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
598 g_error_free(err);
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
599 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601
15799
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
602 /* The query isn't going to happen, so finish the SRV lookup now.
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
603 * Asynchronously call the callback since stuff may not expect
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
604 * the callback to be called before this returns */
76bdff454d6f Minor cleanup.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15712
diff changeset
605 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
606 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
607
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 return query_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
613 purple_srv_cancel(PurpleSrvQueryData *query_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 if (query_data->handle > 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15712
diff changeset
616 purple_input_remove(query_data->handle);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 if (query_data->resolver != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 * 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
622 * 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
623 * finish.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 */
25170
d853f56dad8b dnssrv.c:
Paul Aurich <paul@darkrain42.org>
parents: 25144
diff changeset
625 query_data->cb.srv = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 g_free(query_data->query);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 g_free(query_data->error_message);
20232
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
630 #else
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
631 close(query_data->fd_out);
b7c0c79585f9 applied changes from 31d62e1a78974a0239e86bfeb42b29ab75216114
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
632 close(query_data->fd_in);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 g_free(query_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635 }
25035
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
636
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
637 void
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
638 purple_txt_cancel(PurpleSrvQueryData *query_data)
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
639 {
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
640 purple_srv_cancel(query_data);
affaa4c4836e * some code style adjustments in caps.c
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23201
diff changeset
641 }