Mercurial > pidgin
annotate src/dnssrv.c @ 12116:e75ef7aa913e
[gaim-migrate @ 14416]
" This patch implements a replacement for the queuing
system from 1.x. It also obsoletes a previous patch
[#1338873] I submitted to prioritize the unseen states
in gtk conversations.
The attached envelope.png is ripped from the
msgunread.png already included in gaim. It should be
dropped in the pixmaps directory (Makefile.am is
updated accordingly in this patch).
The two separate queuing preferences from 1.x, queuing
messages while away and queuing all new messages (from
docklet), are replaced with a single 3-way preference
for conversations. The new preference is "Hide new IM
conversations". This preference can be set to never,
away and always.
When a gtk conversation is created, it may be placed in
a hidden conversation window instead of being placed
normally. This decision is based upon the preference
and possibly the away state of the account the
conversation is being created for. This *will* effect
conversations the user explicitly requests to be
created, so in these cases the caller must be sure to
present the conversation to the user, using
gaim_gtkconv_present_conversation(). This is done
already in gtkdialogs.c which handles creating
conversations requested by the user from gaim proper
(menus, double-clicking on budy in blist, etc.).
The main advantage to not queuing messages is that the
conversations exist, the message is written to the
conversation (and logged if appropriate) and the unseen
state is set on the conversation. This means no
additional features are needed to track whether there
are queued messages or not, just use the unseen state
on conversations.
Since conversations may not be visible (messages
"queued"), gaim proper needs some notification that
there are messages waiting. I opted for a menutray icon
that shows up when an im conversation has an unseen
message. Clicking this icon will focus (and show if
hidden) the first conversation with an unseen message.
This is essentially the same behavior of the docklet in
cvs right now, except that the icon is only visible
when there is a conversation with an unread message.
The api that is added is flexible enough to allow
either the docklet or the new blist menutray icon to be
visible for conversations of any/all types and for
unseen messages >= any state. Currently they are set to
only IM conversations and only unseen states >= TEXT
(system messages and no log messages will not trigger
blinking the docklet or showing the blist tray icon),
but these could be made preferences relatively easily
in the future. Other plugins could probably benefit as
well: gaim_gtk_conversations_get_first_unseen().
There is probably some limit to comment size, so I'll
stop rambling now. If anyone has more
questions/comments, catch me in #gaim, here or on
gaim-devel."
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 16 Nov 2005 18:17:01 +0000 |
parents | 8d019c4bf454 |
children | 97167ff86683 |
rev | line source |
---|---|
11373 | 1 /** |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
2 * @file dnssrv.c |
11373 | 3 * |
4 * gaim | |
5 * | |
6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
11898 | 22 |
23 #include "internal.h" | |
24 | |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
25 #ifndef _WIN32 |
11373 | 26 #include <resolv.h> |
11630 | 27 #include <arpa/nameser.h> |
11373 | 28 #include <arpa/nameser_compat.h> |
29 #ifndef T_SRV | |
30 #define T_SRV 33 | |
31 #endif | |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
32 #else |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
33 #include <windns.h> |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
34 /* Missing from the mingw headers */ |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
35 #ifndef DNS_TYPE_SRV |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
36 # define DNS_TYPE_SRV 33 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
37 #endif |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
38 #endif |
11373 | 39 |
40 #include "dnssrv.h" | |
41 #include "eventloop.h" | |
42 #include "debug.h" | |
43 | |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
44 #ifndef _WIN32 |
11373 | 45 typedef union { |
46 HEADER hdr; | |
47 u_char buf[1024]; | |
48 } queryans; | |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
49 #else |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
50 static DNS_STATUS (*MyDnsQuery_UTF8) ( |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
51 PCSTR lpstrName, WORD wType, DWORD fOptions, |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
52 PIP4_ARRAY aipServers, PDNS_RECORD* ppQueryResultsSet, |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
53 PVOID* pReserved) = NULL; |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
54 static void (*MyDnsRecordListFree) (PDNS_RECORD pRecordList, |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
55 DNS_FREE_TYPE FreeType) = NULL; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
56 #endif |
11373 | 57 |
58 struct resdata { | |
59 SRVCallback cb; | |
11382 | 60 gpointer extradata; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
61 #ifndef _WIN32 |
11373 | 62 guint handle; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
63 #else |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
64 char *query; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
65 char *errmsg; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
66 GSList *results; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
67 #endif |
11373 | 68 }; |
69 | |
70 static gint responsecompare(gconstpointer ar, gconstpointer br) { | |
71 struct srv_response *a = (struct srv_response*)ar; | |
72 struct srv_response *b = (struct srv_response*)br; | |
73 | |
74 if(a->pref == b->pref) { | |
75 if(a->weight == b->weight) | |
76 return 0; | |
77 if(a->weight < b->weight) | |
78 return -1; | |
79 return 1; | |
80 } | |
81 if(a->pref < b->pref) | |
82 return -1; | |
83 return 1; | |
84 } | |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
85 #ifndef _WIN32 |
11373 | 86 static void resolve(int in, int out) { |
87 GList *ret = NULL; | |
88 struct srv_response *srvres; | |
89 queryans answer; | |
90 int size; | |
91 int qdcount; | |
92 int ancount; | |
11381 | 93 guchar *end; |
94 guchar *cp; | |
11373 | 95 gchar name[256]; |
96 int type, dlen, pref, weight, port; | |
97 gchar query[256]; | |
98 | |
99 if(read(in, query, 256) <= 0) { | |
100 _exit(0); | |
101 } | |
102 size = res_query( query, C_IN, T_SRV, (u_char*)&answer, sizeof( answer)); | |
103 | |
104 qdcount = ntohs(answer.hdr.qdcount); | |
105 ancount = ntohs(answer.hdr.ancount); | |
106 | |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
107 |
11381 | 108 cp = (guchar*)&answer + sizeof(HEADER); |
109 end = (guchar*)&answer + size; | |
11373 | 110 |
111 /* skip over unwanted stuff */ | |
112 while (qdcount-- > 0 && cp < end) { | |
11381 | 113 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256); |
11373 | 114 if(size < 0) goto end; |
115 cp += size + QFIXEDSZ; | |
116 } | |
117 | |
118 while (ancount-- > 0 && cp < end) { | |
11381 | 119 size = dn_expand((unsigned char*)&answer, end, cp, name, 256); |
11373 | 120 if(size < 0) |
121 goto end; | |
122 | |
123 cp += size; | |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
124 |
11373 | 125 NS_GET16(type,cp); |
126 cp += 6; /* skip ttl and class since we already know it */ | |
127 | |
128 NS_GET16(dlen,cp); | |
129 | |
130 if (type == T_SRV) { | |
131 NS_GET16(pref,cp); | |
132 | |
133 NS_GET16(weight, cp); | |
134 | |
135 NS_GET16(port, cp); | |
136 | |
11381 | 137 size = dn_expand( (unsigned char*)&answer, end, cp, name, 256); |
11373 | 138 if(size < 0 ) |
139 goto end; | |
140 | |
141 cp += size; | |
142 | |
143 srvres = g_new0(struct srv_response,1); | |
144 strcpy(srvres->hostname, name); | |
145 srvres->pref = pref; | |
146 srvres->port = port; | |
147 srvres->weight = weight; | |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
148 |
11373 | 149 ret = g_list_insert_sorted(ret, srvres, responsecompare); |
150 } else { | |
151 cp += dlen; | |
152 } | |
153 } | |
154 end: size = g_list_length(ret); | |
11430 | 155 write(out, &size, sizeof(int)); |
11373 | 156 while(g_list_first(ret)) { |
157 write(out, g_list_first(ret)->data, sizeof(struct srv_response)); | |
158 g_free(g_list_first(ret)->data); | |
159 ret = g_list_remove(ret, g_list_first(ret)->data); | |
160 } | |
161 | |
162 /* Should the resolver be reused? | |
163 * There is most likely only 1 SRV queries per prpl... | |
164 */ | |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
165 _exit(0); |
11373 | 166 } |
167 | |
168 static void resolved(gpointer data, gint source, GaimInputCondition cond) { | |
169 int size; | |
170 struct resdata *rdata = (struct resdata*)data; | |
171 struct srv_response *res; | |
172 struct srv_response *tmp; | |
11426 | 173 int i; |
11373 | 174 SRVCallback cb = rdata->cb; |
175 | |
11430 | 176 read(source, &size, sizeof(int)); |
11373 | 177 gaim_debug_info("srv","found %d SRV entries\n", size); |
178 tmp = res = g_malloc0(sizeof(struct srv_response)*size); | |
11426 | 179 i = size; |
180 while(i) { | |
11373 | 181 read(source, tmp++, sizeof(struct srv_response)); |
11426 | 182 i--; |
11373 | 183 } |
11382 | 184 cb(res, size, rdata->extradata); |
11373 | 185 gaim_input_remove(rdata->handle); |
186 g_free(rdata); | |
187 } | |
188 | |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
189 #else /* _WIN32 */ |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
190 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
191 /** The Jabber Server code was inspiration for parts of this. */ |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
192 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
193 static gboolean res_main_thread_cb(gpointer data) { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
194 struct srv_response *srvres = NULL; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
195 int size = 0; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
196 struct resdata *rdata = data; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
197 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
198 if (rdata->errmsg != NULL) { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
199 gaim_debug_error("srv", rdata->errmsg); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
200 g_free(rdata->errmsg); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
201 } else { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
202 struct srv_response *srvres_tmp; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
203 GSList *lst = rdata->results; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
204 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
205 size = g_slist_length(rdata->results); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
206 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
207 srvres_tmp = srvres = g_malloc0(sizeof(struct srv_response) * size); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
208 while (lst) { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
209 memcpy(srvres_tmp++, lst->data, sizeof(struct srv_response)); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
210 g_free(lst->data); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
211 lst = g_slist_remove(lst, lst->data); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
212 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
213 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
214 rdata->results = lst; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
215 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
216 |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
217 gaim_debug_info("srv", "found %d SRV entries\n", size); |
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
218 |
11382 | 219 rdata->cb(srvres, size, rdata->extradata); |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
220 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
221 g_free(rdata->query); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
222 g_free(rdata); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
223 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
224 return FALSE; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
225 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
226 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
227 static gpointer res_thread(gpointer data) { |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
228 DNS_RECORD *dr = NULL; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
229 GSList *lst = NULL; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
230 struct srv_response *srvres; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
231 DNS_SRV_DATA *srv_data; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
232 int type = DNS_TYPE_SRV; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
233 DNS_STATUS ds; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
234 struct resdata *rdata = data; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
235 |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
236 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
|
237 if (ds != ERROR_SUCCESS) { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
238 rdata->errmsg = g_strdup_printf("Couldn't look up SRV record. Error = %d\n", (int) ds); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
239 } else { |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
240 DNS_RECORD *dr_tmp = dr; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
241 while (dr_tmp != NULL) { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
242 /* 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
|
243 if (dr_tmp->wType != type || strcmp(dr_tmp->pName, rdata->query) != 0) { |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
244 dr_tmp = dr_tmp->pNext; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
245 continue; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
246 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
247 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
248 srv_data = &dr_tmp->Data.SRV; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
249 srvres = g_new0(struct srv_response, 1); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
250 strncpy(srvres->hostname, srv_data->pNameTarget, 255); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
251 srvres->hostname[255] = '\0'; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
252 srvres->pref = srv_data->wPriority; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
253 srvres->port = srv_data->wPort; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
254 srvres->weight = srv_data->wWeight; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
255 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
256 lst = g_slist_insert_sorted(lst, srvres, responsecompare); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
257 |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
258 dr_tmp = dr_tmp->pNext; |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
259 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
260 |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
261 MyDnsRecordListFree(dr, DnsFreeRecordList); |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
262 rdata->results = lst; |
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 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
265 /* back to main thread */ |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
266 g_idle_add(res_main_thread_cb, rdata); |
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 return 0; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
269 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
270 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
271 #endif |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
272 |
11444
d3b870be8759
[gaim-migrate @ 13683]
Richard Laager <rlaager@wiktel.com>
parents:
11430
diff
changeset
|
273 void gaim_srv_resolve(const char *protocol, const char *transport, const char *domain, SRVCallback cb, gpointer extradata) { |
11373 | 274 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
|
275 struct resdata *rdata; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
276 #ifndef _WIN32 |
11373 | 277 int in[2], out[2]; |
278 int pid; | |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
279 gaim_debug_info("srv","querying SRV record for %s\n", query); |
11373 | 280 if(pipe(in) || pipe(out)) { |
281 gaim_debug_error("srv", "Could not create pipe\n"); | |
282 g_free(query); | |
11382 | 283 cb(NULL, 0, extradata); |
11373 | 284 return; |
285 } | |
286 | |
287 pid = fork(); | |
288 | |
289 if(pid == -1) { | |
290 gaim_debug_error("srv","Could not create process!\n"); | |
11382 | 291 cb(NULL, 0, extradata); |
11373 | 292 g_free(query); |
293 return; | |
294 } | |
295 /* Child */ | |
296 if( pid == 0 ) { | |
297 close(out[0]); | |
298 close(in[1]); | |
299 resolve(in[0], out[1]); | |
300 } | |
301 | |
302 close(out[1]); | |
303 close(in[0]); | |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
304 |
11373 | 305 if(write(in[1], query, strlen(query)+1)<0) { |
306 gaim_debug_error("srv", "Could not write to SRV resolver\n"); | |
307 } | |
308 rdata = g_new0(struct resdata,1); | |
309 rdata->cb = cb; | |
11382 | 310 rdata->extradata = extradata; |
11373 | 311 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
|
312 |
11373 | 313 g_free(query); |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
314 #else |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
315 GError* err = NULL; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
316 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
317 static gboolean initialized = FALSE; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
318 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
319 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
|
320 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
321 if (!initialized) { |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
322 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
|
323 MyDnsRecordListFree = (void*) wgaim_find_and_loadproc( |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
324 "dnsapi.dll", "DnsRecordListFree"); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
325 initialized = TRUE; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
326 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
327 |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
328 if (!MyDnsQuery_UTF8 || !MyDnsRecordListFree) { |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
329 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
|
330 g_free(query); |
11382 | 331 cb(NULL, 0, extradata); |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
332 return; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
333 } |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
334 |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
335 rdata = g_new0(struct resdata, 1); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
336 rdata->cb = cb; |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
337 rdata->query = query; |
11395
f0e03a3ca3b5
[gaim-migrate @ 13626]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11382
diff
changeset
|
338 rdata->extradata = extradata; |
11379
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 if (!g_thread_create(res_thread, rdata, FALSE, &err)) { |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
341 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
|
342 g_error_free(err); |
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
343 res_main_thread_cb(rdata); |
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 #endif |
11373 | 346 } |
11379
51c189755f1d
[gaim-migrate @ 13605]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11373
diff
changeset
|
347 |