annotate src/dnssrv.c @ 11373:c84c35ee8202

[gaim-migrate @ 13598] adding async SRV resolver committer: Tailor Script <tailor@pidgin.im>
author Thomas Butter <tbutter>
date Tue, 30 Aug 2005 15:28:49 +0000
parents
children 51c189755f1d
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 /**
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
2 * @file srvresolve.c
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 */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
22 #include <glib.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
23 #include <resolv.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
24 #include <stdlib.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
25 #include <arpa/nameser_compat.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
26 #ifndef T_SRV
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
27 #define T_SRV 33
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
28 #endif
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
29
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
30 #include "dnssrv.h"
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
31 #include <stdio.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
32 #include <unistd.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
33 #include <string.h>
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
34 #include "eventloop.h"
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
35 #include "debug.h"
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
36
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
37 typedef union {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
38 HEADER hdr;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
39 u_char buf[1024];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
40 } queryans;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
41
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
42 struct resdata {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
43 SRVCallback cb;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
44 guint handle;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
45 };
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
46
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
47 static gint responsecompare(gconstpointer ar, gconstpointer br) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
48 struct srv_response *a = (struct srv_response*)ar;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
49 struct srv_response *b = (struct srv_response*)br;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
50
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
51 if(a->pref == b->pref) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
52 if(a->weight == b->weight)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
53 return 0;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
54 if(a->weight < b->weight)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
55 return -1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
56 return 1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
57 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
58 if(a->pref < b->pref)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
59 return -1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
60 return 1;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
61 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
62
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
63 static void resolve(int in, int out) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
64 GList *ret = NULL;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
65 struct srv_response *srvres;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
66 queryans answer;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
67 int size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
68 int qdcount;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
69 int ancount;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
70 gchar *end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
71 gchar *cp;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
72 gchar name[256];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
73 int type, dlen, pref, weight, port;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
74 gchar query[256];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
75
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
76 if(read(in, query, 256) <= 0) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
77 _exit(0);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
78 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
79 size = res_query( query, C_IN, T_SRV, (u_char*)&answer, sizeof( answer));
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
80
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
81 qdcount = ntohs(answer.hdr.qdcount);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
82 ancount = ntohs(answer.hdr.ancount);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
83
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
84
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
85 cp = (char*)&answer + sizeof(HEADER);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
86 end = (char*)&answer + size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
87
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
88 /* skip over unwanted stuff */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
89 while (qdcount-- > 0 && cp < end) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
90 size = dn_expand( (char*)&answer, end, cp, name, 256);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
91 if(size < 0) goto end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
92 cp += size + QFIXEDSZ;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
93 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
94
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
95 while (ancount-- > 0 && cp < end) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
96 size = dn_expand((char*)&answer, end, cp, name, 256);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
97 if(size < 0)
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
98 goto end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
99
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
100 cp += size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
101
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
102 NS_GET16(type,cp);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
103 cp += 6; /* skip ttl and class since we already know it */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
104
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
105 NS_GET16(dlen,cp);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
106
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
107 if (type == T_SRV) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
108 NS_GET16(pref,cp);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
109
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
110 NS_GET16(weight, cp);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
111
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
112 NS_GET16(port, cp);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
113
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
114 size = dn_expand( (char*)&answer, end, cp, name, 256);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
115 if(size < 0 )
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
116 goto end;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
117
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
118 cp += size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
119
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
120 srvres = g_new0(struct srv_response,1);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
121 strcpy(srvres->hostname, name);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
122 srvres->pref = pref;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
123 srvres->port = port;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
124 srvres->weight = weight;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
125
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
126 ret = g_list_insert_sorted(ret, srvres, responsecompare);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
127 } else {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
128 cp += dlen;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
129 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
130 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
131 end: size = g_list_length(ret);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
132 write(out, &size, 4);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
133 while(g_list_first(ret)) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
134 write(out, g_list_first(ret)->data, sizeof(struct srv_response));
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
135 g_free(g_list_first(ret)->data);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
136 ret = g_list_remove(ret, g_list_first(ret)->data);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
137 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
138
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
139 /* Should the resolver be reused?
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
140 * There is most likely only 1 SRV queries per prpl...
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
141 */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
142 _exit(0);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
143 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
144
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
145 static void resolved(gpointer data, gint source, GaimInputCondition cond) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
146 int size;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
147 struct resdata *rdata = (struct resdata*)data;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
148 struct srv_response *res;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
149 struct srv_response *tmp;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
150 SRVCallback cb = rdata->cb;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
151
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
152 read(source, &size, 4);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
153 gaim_debug_info("srv","found %d SRV entries\n", size);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
154 tmp = res = g_malloc0(sizeof(struct srv_response)*size);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
155 while(size) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
156 read(source, tmp++, sizeof(struct srv_response));
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
157 size--;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
158 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
159 cb(res, size);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
160 gaim_input_remove(rdata->handle);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
161 g_free(rdata);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
162 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
163
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
164 void gaim_srv_resolve(char *protocol, char *transport, char *domain, SRVCallback cb) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
165 char *query = g_strdup_printf("_%s._%s.%s",protocol, transport, domain);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
166 int in[2], out[2];
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
167 int pid;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
168 struct resdata *rdata;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
169 gaim_debug_info("dnssrv","querying SRV record for %s\n",query);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
170 if(pipe(in) || pipe(out)) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
171 gaim_debug_error("srv", "Could not create pipe\n");
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
172 g_free(query);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
173 cb(NULL, 0);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
174 return;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
175 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
176
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
177 pid = fork();
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
178
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
179 if(pid == -1) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
180 gaim_debug_error("srv","Could not create process!\n");
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
181 cb(NULL, 0);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
182 g_free(query);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
183 return;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
184 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
185 /* Child */
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
186 if( pid == 0 ) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
187 close(out[0]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
188 close(in[1]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
189 resolve(in[0], out[1]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
190 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
191
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
192 close(out[1]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
193 close(in[0]);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
194
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
195 if(write(in[1], query, strlen(query)+1)<0) {
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
196 gaim_debug_error("srv", "Could not write to SRV resolver\n");
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
197 }
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
198 rdata = g_new0(struct resdata,1);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
199 rdata->cb = cb;
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
200 rdata->handle = gaim_input_add(out[0], GAIM_INPUT_READ, resolved, rdata);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
201 g_free(query);
c84c35ee8202 [gaim-migrate @ 13598]
Thomas Butter <tbutter>
parents:
diff changeset
202 }