annotate src/dnssrv.c @ 13294:8cecf7929eb3

[gaim-migrate @ 15660] Sean apparently doesn't build with dbus. committer: Tailor Script <tailor@pidgin.im>
author Etan Reisner <pidgin@unreliablesource.net>
date Thu, 16 Feb 2006 01:41:52 +0000
parents 386a4f784cde
children b9404076ef67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
1 /**
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
2 * @file dnssrv.c
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
3 *
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
4 * gaim
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
5 *
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
7 *
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
11 * (at your option) any later version.
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
12 *
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
16 * GNU General Public License for more details.
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
17 *
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
21 */
11898
8d019c4bf454 [gaim-migrate @ 14189]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11630
diff changeset
22
8d019c4bf454 [gaim-migrate @ 14189]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11630
diff changeset
23 #include "internal.h"
8d019c4bf454 [gaim-migrate @ 14189]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11630
diff changeset
24
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
25 #ifndef _WIN32
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
26 #include <resolv.h>
11630
33cdc34b3a63 [gaim-migrate @ 13905]
Mark Doliner <mark@kingant.net>
parents: 11444
diff changeset
27 #include <arpa/nameser.h>
12568
17a85606bcc8 [gaim-migrate @ 14887]
Richard Laager <rlaager@wiktel.com>
parents: 12451
diff changeset
28 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
29 #include <arpa/nameser_compat.h>
12568
17a85606bcc8 [gaim-migrate @ 14887]
Richard Laager <rlaager@wiktel.com>
parents: 12451
diff changeset
30 #endif
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
31 #ifndef T_SRV
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
32 #define T_SRV 33
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
33 #endif
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
34 #else
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
35 #include <windns.h>
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
36 /* Missing from the mingw headers */
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
37 #ifndef DNS_TYPE_SRV
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
38 # define DNS_TYPE_SRV 33
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
39 #endif
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
40 #endif
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
41
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
42 #include "dnssrv.h"
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
43 #include "eventloop.h"
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
44 #include "debug.h"
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
45
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
46 #ifndef _WIN32
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
47 typedef union {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
48 HEADER hdr;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
49 u_char buf[1024];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
50 } queryans;
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
51 #else
12847
a95094ac6766 [gaim-migrate @ 15195]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12691
diff changeset
52 static DNS_STATUS WINAPI (*MyDnsQuery_UTF8) (
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
53 PCSTR lpstrName, WORD wType, DWORD fOptions,
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
54 PIP4_ARRAY aipServers, PDNS_RECORD* ppQueryResultsSet,
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
55 PVOID* pReserved) = NULL;
12847
a95094ac6766 [gaim-migrate @ 15195]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12691
diff changeset
56 static void WINAPI (*MyDnsRecordListFree) (PDNS_RECORD pRecordList,
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
57 DNS_FREE_TYPE FreeType) = NULL;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
58 #endif
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
59
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
60 struct resdata {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
61 GaimSRVCallback cb;
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
62 gpointer extradata;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
63 #ifndef _WIN32
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
64 guint handle;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
65 #else
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
66 char *query;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
67 char *errmsg;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
68 GSList *results;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
69 #endif
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
70 };
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
71
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
72 static gint responsecompare(gconstpointer ar, gconstpointer br) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
73 GaimSrvResponse *a = (GaimSrvResponse*)ar;
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
74 GaimSrvResponse *b = (GaimSrvResponse*)br;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
75
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
76 if(a->pref == b->pref) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
77 if(a->weight == b->weight)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
78 return 0;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
79 if(a->weight < b->weight)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
80 return -1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
81 return 1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
82 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
83 if(a->pref < b->pref)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
84 return -1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
85 return 1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
86 }
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
87 #ifndef _WIN32
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
88 static void resolve(int in, int out) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
89 GList *ret = NULL;
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
90 GaimSrvResponse *srvres;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
91 queryans answer;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
92 int size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
93 int qdcount;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
94 int ancount;
11381
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
95 guchar *end;
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
96 guchar *cp;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
97 gchar name[256];
13126
a36053525b79 [gaim-migrate @ 15488]
Mark Doliner <mark@kingant.net>
parents: 12847
diff changeset
98 guint16 type, dlen, pref, weight, port;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
99 gchar query[256];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
100
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
101 if(read(in, query, 256) <= 0) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
102 _exit(0);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
103 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
104 size = res_query( query, C_IN, T_SRV, (u_char*)&answer, sizeof( answer));
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
105
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
106 qdcount = ntohs(answer.hdr.qdcount);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
107 ancount = ntohs(answer.hdr.ancount);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
108
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
109
11381
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
110 cp = (guchar*)&answer + sizeof(HEADER);
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
111 end = (guchar*)&answer + size;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
112
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
113 /* skip over unwanted stuff */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
114 while (qdcount-- > 0 && cp < end) {
11381
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
115 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
116 if(size < 0) goto end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
117 cp += size + QFIXEDSZ;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
118 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
119
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
120 while (ancount-- > 0 && cp < end) {
11381
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
121 size = dn_expand((unsigned char*)&answer, end, cp, name, 256);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
122 if(size < 0)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
123 goto end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
124
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
125 cp += size;
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
126
13142
386a4f784cde [gaim-migrate @ 15505]
Mark Doliner <mark@kingant.net>
parents: 13126
diff changeset
127 GETSHORT(type,cp);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
128
13126
a36053525b79 [gaim-migrate @ 15488]
Mark Doliner <mark@kingant.net>
parents: 12847
diff changeset
129 /* skip ttl and class since we already know it */
a36053525b79 [gaim-migrate @ 15488]
Mark Doliner <mark@kingant.net>
parents: 12847
diff changeset
130 cp += 6;
a36053525b79 [gaim-migrate @ 15488]
Mark Doliner <mark@kingant.net>
parents: 12847
diff changeset
131
13142
386a4f784cde [gaim-migrate @ 15505]
Mark Doliner <mark@kingant.net>
parents: 13126
diff changeset
132 GETSHORT(dlen,cp);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
133
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
134 if (type == T_SRV) {
13142
386a4f784cde [gaim-migrate @ 15505]
Mark Doliner <mark@kingant.net>
parents: 13126
diff changeset
135 GETSHORT(pref,cp);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
136
13142
386a4f784cde [gaim-migrate @ 15505]
Mark Doliner <mark@kingant.net>
parents: 13126
diff changeset
137 GETSHORT(weight,cp);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
138
13142
386a4f784cde [gaim-migrate @ 15505]
Mark Doliner <mark@kingant.net>
parents: 13126
diff changeset
139 GETSHORT(port,cp);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
140
11381
e0f42900de12 [gaim-migrate @ 13608]
Mark Doliner <mark@kingant.net>
parents: 11379
diff changeset
141 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
142 if(size < 0 )
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
143 goto end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
144
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
145 cp += size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
146
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
147 srvres = g_new0(GaimSrvResponse, 1);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
148 strcpy(srvres->hostname, name);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
149 srvres->pref = pref;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
150 srvres->port = port;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
151 srvres->weight = weight;
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
152
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
153 ret = g_list_insert_sorted(ret, srvres, responsecompare);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
154 } else {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
155 cp += dlen;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
156 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
157 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
158 end: size = g_list_length(ret);
11430
4b7087777411 [gaim-migrate @ 13667]
Thomas Butter <tbutter>
parents: 11426
diff changeset
159 write(out, &size, sizeof(int));
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
160 while(g_list_first(ret)) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
161 write(out, g_list_first(ret)->data, sizeof(GaimSrvResponse));
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
162 g_free(g_list_first(ret)->data);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
163 ret = g_list_remove(ret, g_list_first(ret)->data);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
164 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
165
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
166 /* Should the resolver be reused?
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
167 * There is most likely only 1 SRV queries per prpl...
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
168 */
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
169 _exit(0);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
170 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
171
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
172 static void resolved(gpointer data, gint source, GaimInputCondition cond) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
173 int size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
174 struct resdata *rdata = (struct resdata*)data;
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
175 GaimSrvResponse *res;
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
176 GaimSrvResponse *tmp;
11426
d678a37c16d9 [gaim-migrate @ 13663]
Thomas Butter <tbutter>
parents: 11395
diff changeset
177 int i;
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
178 GaimSRVCallback cb = rdata->cb;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
179
11430
4b7087777411 [gaim-migrate @ 13667]
Thomas Butter <tbutter>
parents: 11426
diff changeset
180 read(source, &size, sizeof(int));
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
181 gaim_debug_info("srv","found %d SRV entries\n", size);
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
182 tmp = res = g_new0(GaimSrvResponse, size);
11426
d678a37c16d9 [gaim-migrate @ 13663]
Thomas Butter <tbutter>
parents: 11395
diff changeset
183 i = size;
d678a37c16d9 [gaim-migrate @ 13663]
Thomas Butter <tbutter>
parents: 11395
diff changeset
184 while(i) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
185 read(source, tmp++, sizeof(GaimSrvResponse));
11426
d678a37c16d9 [gaim-migrate @ 13663]
Thomas Butter <tbutter>
parents: 11395
diff changeset
186 i--;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
187 }
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
188 cb(res, size, rdata->extradata);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
189 gaim_input_remove(rdata->handle);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
190 g_free(rdata);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
191 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
192
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
193 #else /* _WIN32 */
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
194
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
195 /** The Jabber Server code was inspiration for parts of this. */
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
196
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
197 static gboolean res_main_thread_cb(gpointer data) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
198 GaimSrvResponse *srvres = NULL;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
199 int size = 0;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
200 struct resdata *rdata = data;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
201
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
202 if (rdata->errmsg != NULL) {
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
203 gaim_debug_error("srv", rdata->errmsg);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
204 g_free(rdata->errmsg);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
205 } else {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
206 GaimSrvResponse *srvres_tmp;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
207 GSList *lst = rdata->results;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
208
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
209 size = g_slist_length(rdata->results);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
210
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
211 srvres_tmp = srvres = g_new0(GaimSrvResponse, size);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
212 while (lst) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
213 memcpy(srvres_tmp++, lst->data, sizeof(GaimSrvResponse));
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
214 g_free(lst->data);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
215 lst = g_slist_remove(lst, lst->data);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
216 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
217
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
218 rdata->results = lst;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
219 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
220
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
221 gaim_debug_info("srv", "found %d SRV entries\n", size);
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
222
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
223 rdata->cb(srvres, size, rdata->extradata);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
224
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
225 g_free(rdata->query);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
226 g_free(rdata);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
227
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
228 return FALSE;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
229 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
230
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
231 static gpointer res_thread(gpointer data) {
12451
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
232 PDNS_RECORD dr = NULL;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
233 int type = DNS_TYPE_SRV;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
234 DNS_STATUS ds;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
235 struct resdata *rdata = data;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
236
12451
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
237 ds = MyDnsQuery_UTF8(rdata->query, type, DNS_QUERY_STANDARD, NULL, &dr, NULL);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
238 if (ds != ERROR_SUCCESS) {
12691
4e1d44bad3c4 [gaim-migrate @ 15034]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12686
diff changeset
239 gchar *msg = g_win32_error_message(ds);
4e1d44bad3c4 [gaim-migrate @ 15034]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12686
diff changeset
240 rdata->errmsg = g_strdup_printf("Couldn't look up SRV record. %s (%lu).\n", msg, ds);
4e1d44bad3c4 [gaim-migrate @ 15034]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12686
diff changeset
241 g_free(msg);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
242 } else {
12451
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
243 PDNS_RECORD dr_tmp;
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
244 GSList *lst = NULL;
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
245 DNS_SRV_DATA *srv_data;
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
246 GaimSrvResponse *srvres;
12451
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
247
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
248 for (dr_tmp = dr; dr_tmp != NULL; dr_tmp = dr_tmp->pNext) {
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
249 /* Discard any incorrect entries. I'm not sure if this is necessary */
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
250 if (dr_tmp->wType != type || strcmp(dr_tmp->pName, rdata->query) != 0) {
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
251 continue;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
252 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
253
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
254 srv_data = &dr_tmp->Data.SRV;
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
255 srvres = g_new0(GaimSrvResponse, 1);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
256 strncpy(srvres->hostname, srv_data->pNameTarget, 255);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
257 srvres->hostname[255] = '\0';
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
258 srvres->pref = srv_data->wPriority;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
259 srvres->port = srv_data->wPort;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
260 srvres->weight = srv_data->wWeight;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
261
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
262 lst = g_slist_insert_sorted(lst, srvres, responsecompare);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
263 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
264
12451
933fda51587e [gaim-migrate @ 14760]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12439
diff changeset
265 MyDnsRecordListFree(dr, DnsFreeRecordList);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
266 rdata->results = lst;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
267 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
268
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
269 /* back to main thread */
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
270 g_idle_add(res_main_thread_cb, rdata);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
271
12691
4e1d44bad3c4 [gaim-migrate @ 15034]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12686
diff changeset
272 g_thread_exit(NULL);
4e1d44bad3c4 [gaim-migrate @ 15034]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12686
diff changeset
273 return NULL;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
274 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
275
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
276 #endif
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
277
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12568
diff changeset
278 void gaim_srv_resolve(const char *protocol, const char *transport, const char *domain, GaimSRVCallback cb, gpointer extradata) {
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
279 char *query = g_strdup_printf("_%s._%s.%s",protocol, transport, domain);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
280 struct resdata *rdata;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
281 #ifndef _WIN32
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
282 int in[2], out[2];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
283 int pid;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
284 gaim_debug_info("srv","querying SRV record for %s\n", query);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
285 if(pipe(in) || pipe(out)) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
286 gaim_debug_error("srv", "Could not create pipe\n");
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
287 g_free(query);
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
288 cb(NULL, 0, extradata);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
289 return;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
290 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
291
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
292 pid = fork();
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
293
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
294 if(pid == -1) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
295 gaim_debug_error("srv","Could not create process!\n");
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
296 cb(NULL, 0, extradata);
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
297 g_free(query);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
298 return;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
299 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
300 /* Child */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
301 if( pid == 0 ) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
302 close(out[0]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
303 close(in[1]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
304 resolve(in[0], out[1]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
305 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
306
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
307 close(out[1]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
308 close(in[0]);
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
309
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
310 if(write(in[1], query, strlen(query)+1)<0) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
311 gaim_debug_error("srv", "Could not write to SRV resolver\n");
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
312 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
313 rdata = g_new0(struct resdata,1);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
314 rdata->cb = cb;
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
315 rdata->extradata = extradata;
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
316 rdata->handle = gaim_input_add(out[0], GAIM_INPUT_READ, resolved, rdata);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
317
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
318 g_free(query);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
319 #else
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
320 GError* err = NULL;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
321
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
322 static gboolean initialized = FALSE;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
323
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
324 gaim_debug_info("srv","querying SRV record for %s\n", query);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
325
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
326 if (!initialized) {
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
327 MyDnsQuery_UTF8 = (void*) wgaim_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
328 MyDnsRecordListFree = (void*) wgaim_find_and_loadproc(
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
329 "dnsapi.dll", "DnsRecordListFree");
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
330 initialized = TRUE;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
331 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
332
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
333 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) {
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
334 gaim_debug_error("srv", "System missing DNS API (Requires W2K+)\n");
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
335 g_free(query);
11382
bdeace860555 [gaim-migrate @ 13609]
Thomas Butter <tbutter>
parents: 11381
diff changeset
336 cb(NULL, 0, extradata);
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
337 return;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
338 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
339
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
340 rdata = g_new0(struct resdata, 1);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
341 rdata->cb = cb;
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
342 rdata->query = query;
11395
f0e03a3ca3b5 [gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11382
diff changeset
343 rdata->extradata = extradata;
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
344
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
345 if (!g_thread_create(res_thread, rdata, FALSE, &err)) {
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
346 rdata->errmsg = g_strdup_printf("SRV thread create failure: %s\n", err ? err->message : "");
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
347 g_error_free(err);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
348 res_main_thread_cb(rdata);
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
349 }
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
350 #endif
11373
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
351 }
11379
51c189755f1d [gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11373
diff changeset
352