comparison src/protocols/rendezvous/rendezvous.c @ 8594:f3b928825a72

[gaim-migrate @ 9345] Some minor rendezvous changes. You still shouldn't use this yet, it has a long way to go. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 06 Apr 2004 05:16:02 +0000
parents f96795b786d2
children 219e9638e8f3
comparison
equal deleted inserted replaced
8593:ba075b939aa6 8594:f3b928825a72
161 RendezvousData *rd = gc->proto_data; 161 RendezvousData *rd = gc->proto_data;
162 RendezvousBuddy *rb; 162 RendezvousBuddy *rb;
163 GHashTable *rdata; 163 GHashTable *rdata;
164 gchar *tmp1, *tmp2; 164 gchar *tmp1, *tmp2;
165 165
166 rdata = rr->rdata;
167
168 /* Don't do a damn thing if the version is greater than 1 */
169 tmp1 = g_hash_table_lookup(rdata, "version");
170 if ((tmp1 == NULL) || (strcmp(tmp1, "1")))
171 return;
172
166 rb = g_hash_table_lookup(rd->buddies, name); 173 rb = g_hash_table_lookup(rd->buddies, name);
167 if (rb == NULL) { 174 if (rb == NULL) {
168 rb = g_malloc0(sizeof(RendezvousBuddy)); 175 rb = g_malloc0(sizeof(RendezvousBuddy));
169 g_hash_table_insert(rd->buddies, g_strdup(name), rb); 176 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
170 } 177 }
171
172 rdata = rr->rdata;
173 178
174 tmp1 = g_hash_table_lookup(rdata, "1st"); 179 tmp1 = g_hash_table_lookup(rdata, "1st");
175 tmp2 = g_hash_table_lookup(rdata, "last"); 180 tmp2 = g_hash_table_lookup(rdata, "last");
176 g_free(rb->firstandlast); 181 g_free(rb->firstandlast);
177 rb->firstandlast = g_strdup_printf("%s%s%s", 182 rb->firstandlast = g_strdup_printf("%s%s%s",
184 if (tmp1 != NULL) { 189 if (tmp1 != NULL) {
185 g_free(rb->aim); 190 g_free(rb->aim);
186 rb->aim = g_strdup(tmp1); 191 rb->aim = g_strdup(tmp1);
187 } 192 }
188 193
189 tmp1 = g_hash_table_lookup(rdata, "port.p2pj"); 194 /*
190 rb->p2pjport = atoi(tmp1); 195 * We only want to use this port as a back-up. Ideally the port
196 * is specified in a separate, SRV resource record.
197 */
198 if (rb->p2pjport == 0) {
199 tmp1 = g_hash_table_lookup(rdata, "port.p2pj");
200 rb->p2pjport = atoi(tmp1);
201 }
191 202
192 tmp1 = g_hash_table_lookup(rdata, "status"); 203 tmp1 = g_hash_table_lookup(rdata, "status");
193 if (tmp1 != NULL) { 204 if (tmp1 != NULL) {
194 if (!strcmp(tmp1, "dnd")) { 205 if (!strcmp(tmp1, "dnd")) {
195 /* Available */ 206 /* Available */
210 tmp1 = g_hash_table_lookup(rdata, "msg"); 221 tmp1 = g_hash_table_lookup(rdata, "msg");
211 if (tmp1 != NULL) { 222 if (tmp1 != NULL) {
212 g_free(rb->msg); 223 g_free(rb->msg);
213 rb->msg = g_strdup(tmp1); 224 rb->msg = g_strdup(tmp1);
214 } 225 }
215 226 }
216 /* XXX - Use the TTL value of the rr to cause this data to expire */ 227
228 static void rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
229 {
230 RendezvousData *rd = gc->proto_data;
231 RendezvousBuddy *rb;
232 ResourceRecordSRV *rdata;
233
234 rdata = rr->rdata;
235
236 rb = g_hash_table_lookup(rd->buddies, name);
237 if (rb == NULL) {
238 rb = g_malloc0(sizeof(RendezvousBuddy));
239 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
240 }
241
242 rb->p2pjport = rdata->port;
217 } 243 }
218 244
219 /* 245 /*
220 * Parse a resource record and do stuff if we need to. 246 * Parse a resource record and do stuff if we need to.
221 */ 247 */
222 static void rendezvous_handle_rr(GaimConnection *gc, ResourceRecord *rr) 248 static void rendezvous_handle_rr(GaimConnection *gc, ResourceRecord *rr)
223 { 249 {
224 gchar *name; 250 gchar *name;
225 251
226 gaim_debug_error("XXX", "Parsing resource record with domain name %s\n", rr->name); 252 gaim_debug_misc("rendezvous", "Parsing resource record with domain name %s\n", rr->name);
253
254 /*
255 * XXX - Cache resource records from this function, if needed.
256 * Use the TTL value of the rr to cause this data to expire, but let
257 * the mdns_cache stuff handle that as much as possible.
258 */
227 259
228 switch (rr->type) { 260 switch (rr->type) {
229 case RENDEZVOUS_RRTYPE_NULL: { 261 case RENDEZVOUS_RRTYPE_NULL: {
230 if ((name = rendezvous_extract_name(rr->name)) != NULL) { 262 if ((name = rendezvous_extract_name(rr->name)) != NULL) {
231 if (rr->rdlength > 0) { 263 if (rr->rdlength > 0) {
253 if ((name = rendezvous_extract_name(rr->name)) != NULL) { 285 if ((name = rendezvous_extract_name(rr->name)) != NULL) {
254 rendezvous_handle_rr_txt(gc, rr, name); 286 rendezvous_handle_rr_txt(gc, rr, name);
255 g_free(name); 287 g_free(name);
256 } 288 }
257 } break; 289 } break;
290
291 case RENDEZVOUS_RRTYPE_SRV: {
292 if ((name = rendezvous_extract_name(rr->name)) != NULL) {
293 rendezvous_handle_rr_srv(gc, rr, name);
294 g_free(name);
295 }
296 } break;
258 } 297 }
259 } 298 }
260 299
261 /****************************/ 300 /****************************/
262 /* Icon and Emblem Funtions */ 301 /* Icon and Emblem Funtions */
312 if (rb->status == UC_UNAVAILABLE) 351 if (rb->status == UC_UNAVAILABLE)
313 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Away"), rb->msg); 352 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Away"), rb->msg);
314 else 353 else
315 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Available"), rb->msg); 354 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Available"), rb->msg);
316 } 355 }
317
318 /* XXX - Fix blist.c so we can prepend the \n's rather than appending them */
319 356
320 return g_string_free(ret, FALSE); 357 return g_string_free(ret, FALSE);
321 } 358 }
322 359
323 /****************************/ 360 /****************************/