Mercurial > pidgin.yaz
annotate src/protocols/rendezvous/rendezvous.c @ 9965:269029c55169
[gaim-migrate @ 10874]
I don't even want to know what happened with the merge for rendezvous...
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 08 Sep 2004 00:21:47 +0000 |
parents | a9fb4493ae22 |
children | c124bef68132 |
rev | line source |
---|---|
8487 | 1 /* |
2 * gaim - Rendezvous Protocol Plugin | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
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 */ | |
22 #include "internal.h" | |
23 | |
24 #include "account.h" | |
25 #include "accountopt.h" | |
26 #include "blist.h" | |
27 #include "conversation.h" | |
28 #include "debug.h" | |
8834 | 29 #include "network.h" |
8487 | 30 #include "prpl.h" |
9416 | 31 #include "sha.h" |
8487 | 32 #include "util.h" |
9954 | 33 #include "version.h" |
8487 | 34 |
9965 | 35 #include "rendezvous.h" |
36 #include "mdns.h" | |
8487 | 37 |
38 /****************************/ | |
39 /* Utility Functions */ | |
40 /****************************/ | |
41 static void rendezvous_buddy_free(gpointer data) | |
42 { | |
43 RendezvousBuddy *rb = data; | |
44 | |
45 g_free(rb->firstandlast); | |
46 g_free(rb->msg); | |
47 g_free(rb); | |
48 } | |
49 | |
8546 | 50 /** |
8487 | 51 * Extract the "user@host" name from a full presence domain |
52 * of the form "user@host._presence._tcp.local" | |
53 * | |
54 * @return If the domain is NOT a _presence._tcp.local domain | |
55 * then return NULL. Otherwise return a newly allocated | |
56 * null-terminated string containing the "user@host" for | |
57 * the given domain. This string should be g_free'd | |
58 * when no longer needed. | |
59 */ | |
60 static gchar *rendezvous_extract_name(gchar *domain) | |
61 { | |
62 gchar *ret, *suffix; | |
63 | |
64 if (!g_str_has_suffix(domain, "._presence._tcp.local")) | |
65 return NULL; | |
66 | |
67 suffix = strstr(domain, "._presence._tcp.local"); | |
68 ret = g_strndup(domain, suffix - domain); | |
69 | |
70 return ret; | |
71 } | |
72 | |
73 /****************************/ | |
74 /* Buddy List Functions */ | |
75 /****************************/ | |
8612 | 76 |
8487 | 77 static void rendezvous_addtolocal(GaimConnection *gc, const char *name, const char *domain) |
78 { | |
79 GaimAccount *account = gaim_connection_get_account(gc); | |
80 GaimBuddy *b; | |
81 GaimGroup *g; | |
82 | |
83 g = gaim_find_group(domain); | |
84 if (g == NULL) { | |
85 g = gaim_group_new(domain); | |
86 gaim_blist_add_group(g, NULL); | |
87 } | |
88 | |
89 b = gaim_find_buddy_in_group(account, name, g); | |
90 if (b != NULL) | |
91 return; | |
92 | |
93 b = gaim_buddy_new(account, name, NULL); | |
9817 | 94 /* gaim_blist_node_set_flag(b, GAIM_BLIST_NODE_FLAG_NO_SAVE); */ |
8487 | 95 gaim_blist_add_buddy(b, NULL, g, NULL); |
9965 | 96 serv_got_update(gc, b->name, TRUE, 0); |
8612 | 97 |
98 #if 0 | |
99 RendezvousBuddy *rb; | |
100 rb = g_hash_table_lookup(rd->buddies, name); | |
101 if (rb == NULL) { | |
102 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
103 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
104 } | |
105 rb->ttltimer = gaim_timeout_add(time * 10000, rendezvous_buddy_timeout, gc); | |
106 | |
107 gaim_timeout_remove(rb->ttltimer); | |
108 rb->ttltimer = 0; | |
109 #endif | |
8487 | 110 } |
111 | |
112 static void rendezvous_removefromlocal(GaimConnection *gc, const char *name, const char *domain) | |
113 { | |
114 GaimAccount *account = gaim_connection_get_account(gc); | |
115 GaimBuddy *b; | |
116 GaimGroup *g; | |
117 | |
118 g = gaim_find_group(domain); | |
119 if (g == NULL) | |
120 return; | |
121 | |
122 b = gaim_find_buddy_in_group(account, name, g); | |
123 if (b == NULL) | |
124 return; | |
125 | |
9965 | 126 serv_got_update(gc, b->name, FALSE, 0); |
8487 | 127 gaim_blist_remove_buddy(b); |
8546 | 128 /* XXX - This results in incorrect group counts--needs to be fixed in the core */ |
9289 | 129 /* XXX - We also need to call remove_idle_buddy() in server.c for idle buddies */ |
8612 | 130 |
131 /* | |
132 * XXX - Instead of removing immediately, wait 10 seconds and THEN remove | |
133 * them. If you do it immediately you don't see the door close icon. | |
134 */ | |
8487 | 135 } |
136 | |
137 static void rendezvous_removeallfromlocal(GaimConnection *gc) | |
138 { | |
139 GaimAccount *account = gaim_connection_get_account(gc); | |
140 GaimBuddyList *blist; | |
141 GaimBlistNode *gnode, *cnode, *bnode; | |
142 GaimBuddy *b; | |
143 | |
144 /* Go through and remove all buddies that belong to this account */ | |
145 if ((blist = gaim_get_blist()) != NULL) { | |
146 for (gnode = blist->root; gnode; gnode = gnode->next) { | |
147 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
148 continue; | |
149 for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
150 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
151 continue; | |
152 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
153 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
154 continue; | |
155 b = (GaimBuddy *)bnode; | |
156 if (b->account != account) | |
157 continue; | |
9965 | 158 serv_got_update(gc, b->name, FALSE, 0); |
8487 | 159 gaim_blist_remove_buddy(b); |
160 } | |
161 } | |
162 } | |
163 } | |
164 } | |
165 | |
8834 | 166 static void rendezvous_handle_rr_a(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
167 { | |
168 RendezvousData *rd = gc->proto_data; | |
169 RendezvousBuddy *rb; | |
170 ResourceRecordRDataSRV *rdata; | |
171 | |
172 rdata = rr->rdata; | |
173 | |
174 rb = g_hash_table_lookup(rd->buddies, name); | |
175 if (rb == NULL) { | |
176 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
177 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
178 } | |
179 | |
9965 | 180 #if 0 |
8834 | 181 memcpy(rb->ip, rdata, 4); |
9965 | 182 #endif |
8834 | 183 } |
184 | |
8487 | 185 static void rendezvous_handle_rr_txt(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
186 { | |
187 RendezvousData *rd = gc->proto_data; | |
188 RendezvousBuddy *rb; | |
8806 | 189 GSList *rdata; |
190 ResourceRecordRDataTXTNode *node1, *node2; | |
8487 | 191 |
8594 | 192 rdata = rr->rdata; |
193 | |
194 /* Don't do a damn thing if the version is greater than 1 */ | |
8806 | 195 node1 = mdns_txt_find(rdata, "version"); |
196 if ((node1 == NULL) || (node1->value == NULL) || (strcmp(node1->value, "1"))) | |
8594 | 197 return; |
198 | |
8487 | 199 rb = g_hash_table_lookup(rd->buddies, name); |
200 if (rb == NULL) { | |
201 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
202 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
203 } | |
204 | |
8806 | 205 node1 = mdns_txt_find(rdata, "1st"); |
206 node2 = mdns_txt_find(rdata, "last"); | |
8487 | 207 g_free(rb->firstandlast); |
208 rb->firstandlast = g_strdup_printf("%s%s%s", | |
8806 | 209 (node1 && node1->value ? node1->value : ""), |
210 (node1 && node1->value && node2 && node2->value ? " " : ""), | |
211 (node2 && node2->value ? node2->value : "")); | |
8487 | 212 serv_got_alias(gc, name, rb->firstandlast); |
213 | |
8806 | 214 node1 = mdns_txt_find(rdata, "aim"); |
215 if ((node1 != NULL) && (node1->value != NULL)) { | |
8487 | 216 g_free(rb->aim); |
8806 | 217 rb->aim = g_strdup(node1->value); |
8487 | 218 } |
219 | |
8594 | 220 /* |
221 * We only want to use this port as a back-up. Ideally the port | |
222 * is specified in a separate, SRV resource record. | |
223 */ | |
224 if (rb->p2pjport == 0) { | |
8806 | 225 node1 = mdns_txt_find(rdata, "port.p2pj"); |
226 if ((node1 != NULL) && (node1->value)) | |
227 rb->p2pjport = atoi(node1->value); | |
8594 | 228 } |
8487 | 229 |
9775 | 230 node1 = mdns_txt_find(rdata, "status"); |
8806 | 231 if ((node1 != NULL) && (node1->value != NULL)) { |
232 if (!strcmp(node1->value, "avail")) { | |
8487 | 233 /* Available */ |
234 rb->status = 0; | |
8806 | 235 } else if (!strcmp(node1->value, "away")) { |
8487 | 236 /* Idle */ |
8806 | 237 node2 = mdns_txt_find(rdata, "away"); |
238 if ((node2 != NULL) && (node2->value)) { | |
9289 | 239 /* Time is seconds since January 1st 2001 GMT */ |
8806 | 240 rb->idle = atoi(node2->value); |
9289 | 241 rb->idle += 978307200; /* convert to seconds-since-epoch */ |
8806 | 242 } |
8487 | 243 rb->status = UC_IDLE; |
8806 | 244 } else if (!strcmp(node1->value, "dnd")) { |
8487 | 245 /* Away */ |
246 rb->status = UC_UNAVAILABLE; | |
247 } | |
9965 | 248 serv_got_update(gc, name, TRUE, 0); |
249 /* XXX - Idle time is rb->idle and status is rb->status */ | |
8487 | 250 } |
251 | |
8806 | 252 node1 = mdns_txt_find(rdata, "msg"); |
253 if ((node1 != NULL) && (node1->value != NULL)) { | |
8487 | 254 g_free(rb->msg); |
8806 | 255 rb->msg = g_strdup(node1->value); |
8487 | 256 } |
8594 | 257 } |
8546 | 258 |
8594 | 259 static void rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
260 { | |
261 RendezvousData *rd = gc->proto_data; | |
262 RendezvousBuddy *rb; | |
8806 | 263 ResourceRecordRDataSRV *rdata; |
8594 | 264 |
265 rdata = rr->rdata; | |
266 | |
267 rb = g_hash_table_lookup(rd->buddies, name); | |
268 if (rb == NULL) { | |
269 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
270 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
271 } | |
272 | |
273 rb->p2pjport = rdata->port; | |
8487 | 274 } |
275 | |
276 /* | |
277 * Parse a resource record and do stuff if we need to. | |
278 */ | |
279 static void rendezvous_handle_rr(GaimConnection *gc, ResourceRecord *rr) | |
280 { | |
8636 | 281 RendezvousData *rd = gc->proto_data; |
8487 | 282 gchar *name; |
283 | |
8594 | 284 gaim_debug_misc("rendezvous", "Parsing resource record with domain name %s\n", rr->name); |
285 | |
8834 | 286 switch (rr->type) { |
287 case RENDEZVOUS_RRTYPE_A: { | |
288 name = rendezvous_extract_name(rr->name); | |
289 if (name != NULL) { | |
290 rendezvous_handle_rr_a(gc, rr, name); | |
291 g_free(name); | |
292 } | |
293 } break; | |
8487 | 294 |
295 case RENDEZVOUS_RRTYPE_NULL: { | |
8834 | 296 name = rendezvous_extract_name(rr->name); |
297 if (name != NULL) { | |
8487 | 298 if (rr->rdlength > 0) { |
299 /* Data is a buddy icon */ | |
300 gaim_buddy_icons_set_for_user(gaim_connection_get_account(gc), name, rr->rdata, rr->rdlength); | |
301 } | |
302 | |
303 g_free(name); | |
304 } | |
305 } break; | |
306 | |
307 case RENDEZVOUS_RRTYPE_PTR: { | |
308 gchar *rdata = rr->rdata; | |
8834 | 309 |
310 name = rendezvous_extract_name(rdata); | |
311 if (name != NULL) { | |
8636 | 312 if (rr->ttl > 0) { |
313 /* Add them to our buddy list and request their icon */ | |
8487 | 314 rendezvous_addtolocal(gc, name, "Rendezvous"); |
8636 | 315 mdns_query(rd->fd, rdata, RENDEZVOUS_RRTYPE_NULL); |
316 } else { | |
317 /* Remove them from our buddy list */ | |
8487 | 318 rendezvous_removefromlocal(gc, name, "Rendezvous"); |
8636 | 319 } |
8487 | 320 g_free(name); |
321 } | |
322 } break; | |
323 | |
324 case RENDEZVOUS_RRTYPE_TXT: { | |
8834 | 325 name = rendezvous_extract_name(rr->name); |
326 if (name != NULL) { | |
8487 | 327 rendezvous_handle_rr_txt(gc, rr, name); |
328 g_free(name); | |
329 } | |
330 } break; | |
8594 | 331 |
332 case RENDEZVOUS_RRTYPE_SRV: { | |
8834 | 333 name = rendezvous_extract_name(rr->name); |
334 if (name != NULL) { | |
8594 | 335 rendezvous_handle_rr_srv(gc, rr, name); |
336 g_free(name); | |
337 } | |
338 } break; | |
8487 | 339 } |
340 } | |
341 | |
342 /****************************/ | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8721
diff
changeset
|
343 /* Icon and Emblem Functions */ |
8487 | 344 /****************************/ |
345 static const char* rendezvous_prpl_list_icon(GaimAccount *a, GaimBuddy *b) | |
346 { | |
347 return "rendezvous"; | |
348 } | |
349 | |
9965 | 350 static void rendezvous_prpl_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) |
8487 | 351 { |
352 if (GAIM_BUDDY_IS_ONLINE(b)) { | |
353 if (b->uc & UC_UNAVAILABLE) | |
354 *se = "away"; | |
355 } else { | |
356 *se = "offline"; | |
357 } | |
358 } | |
359 | |
360 static gchar *rendezvous_prpl_status_text(GaimBuddy *b) | |
361 { | |
362 GaimConnection *gc = b->account->gc; | |
363 RendezvousData *rd = gc->proto_data; | |
364 RendezvousBuddy *rb; | |
365 gchar *ret; | |
366 | |
367 rb = g_hash_table_lookup(rd->buddies, b->name); | |
368 if ((rb == NULL) || (rb->msg == NULL)) | |
369 return NULL; | |
370 | |
371 ret = g_strdup(rb->msg); | |
372 | |
373 return ret; | |
374 } | |
375 | |
376 static gchar *rendezvous_prpl_tooltip_text(GaimBuddy *b) | |
377 { | |
378 GaimConnection *gc = b->account->gc; | |
379 RendezvousData *rd = gc->proto_data; | |
380 RendezvousBuddy *rb; | |
381 GString *ret; | |
382 | |
383 rb = g_hash_table_lookup(rd->buddies, b->name); | |
384 if (rb == NULL) | |
385 return NULL; | |
386 | |
387 ret = g_string_new(""); | |
388 | |
389 if (rb->aim != NULL) | |
8591 | 390 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("AIM Screen name"), rb->aim); |
8487 | 391 |
392 if (rb->msg != NULL) { | |
393 if (rb->status == UC_UNAVAILABLE) | |
8591 | 394 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Away"), rb->msg); |
8487 | 395 else |
8591 | 396 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Available"), rb->msg); |
8487 | 397 } |
398 | |
399 return g_string_free(ret, FALSE); | |
400 } | |
401 | |
402 /****************************/ | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8721
diff
changeset
|
403 /* Connection Functions */ |
8487 | 404 /****************************/ |
405 static void rendezvous_callback(gpointer data, gint source, GaimInputCondition condition) | |
406 { | |
407 GaimConnection *gc = data; | |
408 RendezvousData *rd = gc->proto_data; | |
409 DNSPacket *dns; | |
8806 | 410 GSList *cur; |
8487 | 411 |
412 gaim_debug_misc("rendezvous", "Received rendezvous datagram\n"); | |
413 | |
414 dns = mdns_read(rd->fd); | |
415 if (dns == NULL) | |
416 return; | |
417 | |
418 /* Handle the DNS packet */ | |
8806 | 419 for (cur = dns->answers; cur != NULL; cur = cur->next) |
420 rendezvous_handle_rr(gc, cur->data); | |
421 for (cur = dns->authority; cur != NULL; cur = cur->next) | |
422 rendezvous_handle_rr(gc, cur->data); | |
423 for (cur = dns->additional; cur != NULL; cur = cur->next) | |
424 rendezvous_handle_rr(gc, cur->data); | |
8487 | 425 |
426 mdns_free(dns); | |
427 } | |
428 | |
8629 | 429 static void rendezvous_add_to_txt(RendezvousData *rd, const char *name, const char *value) |
430 { | |
8631 | 431 ResourceRecordRDataTXTNode *node; |
432 node = g_malloc(sizeof(ResourceRecordRDataTXTNode)); | |
8629 | 433 node->name = g_strdup(name); |
434 node->value = value != NULL ? g_strdup(value) : NULL; | |
435 rd->mytxtdata = g_slist_append(rd->mytxtdata, node); | |
436 } | |
437 | |
9416 | 438 static guchar *rendezvous_read_icon_data(const char *filename, unsigned short *length) |
439 { | |
440 struct stat st; | |
441 FILE *file; | |
442 guchar *data; | |
443 | |
444 *length = 0; | |
445 | |
446 g_return_val_if_fail(filename != NULL, NULL); | |
447 | |
448 if (stat(filename, &st)) | |
449 return NULL; | |
450 | |
451 if (!(file = fopen(filename, "rb"))) | |
452 return NULL; | |
453 | |
454 *length = st.st_size; | |
455 data = g_malloc(*length); | |
456 fread(data, 1, *length, file); | |
457 fclose(file); | |
458 | |
459 return data; | |
460 } | |
461 | |
462 static void rendezvous_add_to_txt_iconhash(RendezvousData *rd, const char *iconfile) | |
463 { | |
464 guchar *icondata; | |
465 unsigned short iconlength; | |
466 unsigned char hash[20]; | |
467 gchar *base16; | |
468 | |
469 g_return_if_fail(rd != NULL); | |
470 | |
471 if (iconfile == NULL) | |
472 return; | |
473 | |
474 icondata = rendezvous_read_icon_data(iconfile, &iconlength); | |
475 shaBlock((unsigned char *)icondata, iconlength, hash); | |
476 g_free(icondata); | |
477 | |
478 base16 = gaim_base16_encode(hash, 20); | |
479 rendezvous_add_to_txt(rd, "phsh", base16); | |
480 g_free(base16); | |
481 } | |
482 | |
8636 | 483 static void rendezvous_send_icon(GaimConnection *gc) |
484 { | |
485 RendezvousData *rd = gc->proto_data; | |
486 GaimAccount *account = gaim_connection_get_account(gc); | |
487 const char *iconfile = gaim_account_get_buddy_icon(account); | |
488 unsigned char *rdata; | |
489 unsigned short rdlength; | |
490 gchar *myname; | |
491 | |
492 if (iconfile == NULL) | |
493 return; | |
494 | |
9416 | 495 rdata = rendezvous_read_icon_data(iconfile, &rdlength); |
8636 | 496 |
497 myname = g_strdup_printf("%s._presence._tcp.local", gaim_account_get_username(account)); | |
498 mdns_advertise_null(rd->fd, myname, rdata, rdlength); | |
499 g_free(myname); | |
8695 | 500 |
501 g_free(rdata); | |
8636 | 502 } |
503 | |
8629 | 504 static void rendezvous_send_online(GaimConnection *gc) |
505 { | |
506 RendezvousData *rd = gc->proto_data; | |
507 GaimAccount *account = gaim_connection_get_account(gc); | |
8636 | 508 const gchar *me; |
509 gchar *myname, *mycomp; | |
8840 | 510 unsigned char myip[4]; |
8629 | 511 |
8631 | 512 me = gaim_account_get_username(account); |
513 myname = g_strdup_printf("%s._presence._tcp.local", me); | |
514 mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1); | |
8840 | 515 /* myip = gaim_network_ip_atoi(gaim_network_get_local_system_ip(-1)); */ |
516 myip[0] = 192; | |
517 myip[1] = 168; | |
518 myip[2] = 1; | |
519 myip[3] = 41; | |
8631 | 520 |
8834 | 521 mdns_advertise_a(rd->fd, mycomp, myip); |
8631 | 522 mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname); |
523 mdns_advertise_srv(rd->fd, myname, 5298, mycomp); | |
8629 | 524 |
525 rendezvous_add_to_txt(rd, "txtvers", "1"); | |
526 rendezvous_add_to_txt(rd, "status", "avail"); | |
8631 | 527 /* rendezvous_add_to_txt(rd, "vc", "A!"); */ |
9416 | 528 rendezvous_add_to_txt_iconhash(rd, gaim_account_get_buddy_icon(account)); |
8629 | 529 rendezvous_add_to_txt(rd, "1st", gaim_account_get_string(account, "first", "Gaim")); |
8631 | 530 if (gaim_account_get_bool(account, "shareaim", FALSE)) { |
531 GList *l; | |
532 GaimAccount *cur; | |
533 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
534 cur = (GaimAccount *)l->data; | |
535 if (!strcmp(gaim_account_get_protocol_id(cur), "prpl-oscar")) { | |
8634 | 536 /* XXX - Should the name be normalized? */ |
8631 | 537 rendezvous_add_to_txt(rd, "AIM", gaim_account_get_username(cur)); |
538 break; | |
539 } | |
540 } | |
541 } | |
8629 | 542 rendezvous_add_to_txt(rd, "version", "1"); |
8631 | 543 rendezvous_add_to_txt(rd, "msg", "Groovin'"); |
8629 | 544 rendezvous_add_to_txt(rd, "port.p2pj", "5298"); |
545 rendezvous_add_to_txt(rd, "last", gaim_account_get_string(account, "last", _("User"))); | |
8631 | 546 mdns_advertise_txt(rd->fd, myname, rd->mytxtdata); |
8629 | 547 |
8636 | 548 rendezvous_send_icon(gc); |
549 | |
8631 | 550 g_free(myname); |
551 g_free(mycomp); | |
8629 | 552 } |
553 | |
8487 | 554 static void rendezvous_prpl_login(GaimAccount *account) |
555 { | |
556 GaimConnection *gc = gaim_account_get_connection(account); | |
557 RendezvousData *rd; | |
558 | |
559 rd = g_new0(RendezvousData, 1); | |
560 rd->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, rendezvous_buddy_free); | |
561 gc->proto_data = rd; | |
562 | |
563 gaim_connection_update_progress(gc, _("Preparing Buddy List"), 0, RENDEZVOUS_CONNECT_STEPS); | |
564 rendezvous_removeallfromlocal(gc); | |
565 | |
566 gaim_connection_update_progress(gc, _("Connecting"), 1, RENDEZVOUS_CONNECT_STEPS); | |
8834 | 567 rd->fd = mdns_socket_establish(); |
8487 | 568 if (rd->fd == -1) { |
569 gaim_connection_error(gc, _("Unable to login to rendezvous")); | |
570 return; | |
571 } | |
572 | |
573 gc->inpa = gaim_input_add(rd->fd, GAIM_INPUT_READ, rendezvous_callback, gc); | |
574 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
575 | |
8636 | 576 mdns_query(rd->fd, "_presence._tcp.local", RENDEZVOUS_RRTYPE_ALL); |
8629 | 577 rendezvous_send_online(gc); |
8487 | 578 } |
579 | |
580 static void rendezvous_prpl_close(GaimConnection *gc) | |
581 { | |
582 RendezvousData *rd = (RendezvousData *)gc->proto_data; | |
8631 | 583 ResourceRecordRDataTXTNode *node; |
8487 | 584 |
585 if (gc->inpa) | |
586 gaim_input_remove(gc->inpa); | |
587 | |
588 rendezvous_removeallfromlocal(gc); | |
589 | |
590 if (!rd) | |
591 return; | |
592 | |
8834 | 593 mdns_socket_close(rd->fd); |
8487 | 594 |
595 g_hash_table_destroy(rd->buddies); | |
596 | |
8629 | 597 while (rd->mytxtdata != NULL) { |
598 node = rd->mytxtdata->data; | |
599 rd->mytxtdata = g_slist_remove(rd->mytxtdata, node); | |
600 g_free(node->name); | |
601 g_free(node->value); | |
602 g_free(node); | |
603 } | |
604 | |
8487 | 605 g_free(rd); |
606 } | |
607 | |
608 static int rendezvous_prpl_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags) | |
609 { | |
610 gaim_debug_info("rendezvous", "Sending IM\n"); | |
611 | |
612 return 1; | |
613 } | |
614 | |
615 static GaimPlugin *my_protocol = NULL; | |
616 | |
8842 | 617 static GaimPluginProtocolInfo prpl_info; |
8487 | 618 |
619 static GaimPluginInfo info = | |
620 { | |
9954 | 621 GAIM_PLUGIN_MAGIC, |
622 GAIM_MAJOR_VERSION, | |
623 GAIM_MINOR_VERSION, | |
8487 | 624 GAIM_PLUGIN_PROTOCOL, /**< type */ |
625 NULL, /**< ui_requirement */ | |
626 0, /**< flags */ | |
627 NULL, /**< dependencies */ | |
628 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
629 | |
630 "prpl-rendezvous", /**< id */ | |
631 "Rendezvous", /**< name */ | |
632 VERSION, /**< version */ | |
633 /** summary */ | |
634 N_("Rendezvous Protocol Plugin"), | |
635 /** description */ | |
636 N_("Rendezvous Protocol Plugin"), | |
637 NULL, /**< author */ | |
638 GAIM_WEBSITE, /**< homepage */ | |
639 | |
640 NULL, /**< load */ | |
641 NULL, /**< unload */ | |
642 NULL, /**< destroy */ | |
643 | |
644 NULL, /**< ui_info */ | |
8993 | 645 &prpl_info, /**< extra_info */ |
646 NULL, | |
647 NULL | |
8487 | 648 }; |
649 | |
650 static void init_plugin(GaimPlugin *plugin) | |
651 { | |
652 GaimAccountUserSplit *split; | |
653 GaimAccountOption *option; | |
8631 | 654 char hostname[255]; |
655 | |
9318 | 656 prpl_info.options = OPT_PROTO_NO_PASSWORD; |
657 prpl_info.icon_spec.format = "jpeg"; | |
658 prpl_info.icon_spec.min_width = 0; | |
659 prpl_info.icon_spec.min_height = 0; | |
660 prpl_info.icon_spec.max_width = 0; | |
661 prpl_info.icon_spec.max_height = 0; | |
9394 | 662 prpl_info.icon_spec.scale_rules = 0; |
9318 | 663 prpl_info.list_icon = rendezvous_prpl_list_icon; |
664 prpl_info.list_emblems = rendezvous_prpl_list_emblems; | |
665 prpl_info.status_text = rendezvous_prpl_status_text; | |
666 prpl_info.tooltip_text = rendezvous_prpl_tooltip_text; | |
667 prpl_info.login = rendezvous_prpl_login; | |
668 prpl_info.close = rendezvous_prpl_close; | |
669 prpl_info.send_im = rendezvous_prpl_send_im; | |
8842 | 670 |
8631 | 671 if (gethostname(hostname, 255) != 0) { |
672 gaim_debug_warning("rendezvous", "Error %d when getting host name. Using \"localhost.\"\n", errno); | |
673 strcpy(hostname, "localhost"); | |
674 } | |
8487 | 675 |
676 /* Try to avoid making this configurable... */ | |
8842 | 677 split = gaim_account_user_split_new(_("Host name"), hostname, '@'); |
8487 | 678 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
679 | |
8842 | 680 option = gaim_account_option_string_new(_("First name"), "first", "Gaim"); |
8487 | 681 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
682 option); | |
683 | |
8842 | 684 option = gaim_account_option_string_new(_("Last name"), "last", _("User")); |
8487 | 685 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
686 option); | |
687 | |
8631 | 688 option = gaim_account_option_bool_new(_("Share AIM screen name"), "shareaim", FALSE); |
8487 | 689 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
690 option); | |
691 | |
692 my_protocol = plugin; | |
693 } | |
694 | |
695 GAIM_INIT_PLUGIN(rendezvous, init_plugin, info); |