Mercurial > pidgin.yaz
annotate src/protocols/rendezvous/rendezvous.c @ 10009:c124bef68132
[gaim-migrate @ 10926]
Thou shalt NULL terminate va_lists!
This fixes the crash-at-startup bug I mentioned in my commit
of Dave West's stuff last night.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 10 Sep 2004 19:51:52 +0000 |
parents | 269029c55169 |
children | 32467b63f55a |
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); |
10009 | 96 gaim_prpl_got_user_status(account, b->name, "online", NULL); |
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 | |
10009 | 126 gaim_prpl_got_user_status(account, b->name, "offline", NULL); |
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; | |
10009 | 158 gaim_prpl_got_user_status(account, b->name, "offline", NULL); |
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; |
10009 | 244 gaim_prpl_got_user_idle(account, b->name, TRUE, rb->idle); |
8806 | 245 } else if (!strcmp(node1->value, "dnd")) { |
8487 | 246 /* Away */ |
247 rb->status = UC_UNAVAILABLE; | |
248 } | |
10009 | 249 gaim_prpl_got_user_status(account, b->name, "online", NULL); |
9965 | 250 /* XXX - Idle time is rb->idle and status is rb->status */ |
8487 | 251 } |
252 | |
8806 | 253 node1 = mdns_txt_find(rdata, "msg"); |
254 if ((node1 != NULL) && (node1->value != NULL)) { | |
8487 | 255 g_free(rb->msg); |
8806 | 256 rb->msg = g_strdup(node1->value); |
8487 | 257 } |
8594 | 258 } |
8546 | 259 |
8594 | 260 static void rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
261 { | |
262 RendezvousData *rd = gc->proto_data; | |
263 RendezvousBuddy *rb; | |
8806 | 264 ResourceRecordRDataSRV *rdata; |
8594 | 265 |
266 rdata = rr->rdata; | |
267 | |
268 rb = g_hash_table_lookup(rd->buddies, name); | |
269 if (rb == NULL) { | |
270 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
271 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
272 } | |
273 | |
274 rb->p2pjport = rdata->port; | |
8487 | 275 } |
276 | |
277 /* | |
278 * Parse a resource record and do stuff if we need to. | |
279 */ | |
280 static void rendezvous_handle_rr(GaimConnection *gc, ResourceRecord *rr) | |
281 { | |
8636 | 282 RendezvousData *rd = gc->proto_data; |
8487 | 283 gchar *name; |
284 | |
8594 | 285 gaim_debug_misc("rendezvous", "Parsing resource record with domain name %s\n", rr->name); |
286 | |
8834 | 287 switch (rr->type) { |
288 case RENDEZVOUS_RRTYPE_A: { | |
289 name = rendezvous_extract_name(rr->name); | |
290 if (name != NULL) { | |
291 rendezvous_handle_rr_a(gc, rr, name); | |
292 g_free(name); | |
293 } | |
294 } break; | |
8487 | 295 |
296 case RENDEZVOUS_RRTYPE_NULL: { | |
8834 | 297 name = rendezvous_extract_name(rr->name); |
298 if (name != NULL) { | |
8487 | 299 if (rr->rdlength > 0) { |
300 /* Data is a buddy icon */ | |
301 gaim_buddy_icons_set_for_user(gaim_connection_get_account(gc), name, rr->rdata, rr->rdlength); | |
302 } | |
303 | |
304 g_free(name); | |
305 } | |
306 } break; | |
307 | |
308 case RENDEZVOUS_RRTYPE_PTR: { | |
309 gchar *rdata = rr->rdata; | |
8834 | 310 |
311 name = rendezvous_extract_name(rdata); | |
312 if (name != NULL) { | |
8636 | 313 if (rr->ttl > 0) { |
314 /* Add them to our buddy list and request their icon */ | |
8487 | 315 rendezvous_addtolocal(gc, name, "Rendezvous"); |
8636 | 316 mdns_query(rd->fd, rdata, RENDEZVOUS_RRTYPE_NULL); |
317 } else { | |
318 /* Remove them from our buddy list */ | |
8487 | 319 rendezvous_removefromlocal(gc, name, "Rendezvous"); |
8636 | 320 } |
8487 | 321 g_free(name); |
322 } | |
323 } break; | |
324 | |
325 case RENDEZVOUS_RRTYPE_TXT: { | |
8834 | 326 name = rendezvous_extract_name(rr->name); |
327 if (name != NULL) { | |
8487 | 328 rendezvous_handle_rr_txt(gc, rr, name); |
329 g_free(name); | |
330 } | |
331 } break; | |
8594 | 332 |
333 case RENDEZVOUS_RRTYPE_SRV: { | |
8834 | 334 name = rendezvous_extract_name(rr->name); |
335 if (name != NULL) { | |
8594 | 336 rendezvous_handle_rr_srv(gc, rr, name); |
337 g_free(name); | |
338 } | |
339 } break; | |
8487 | 340 } |
341 } | |
342 | |
343 /****************************/ | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8721
diff
changeset
|
344 /* Icon and Emblem Functions */ |
8487 | 345 /****************************/ |
346 static const char* rendezvous_prpl_list_icon(GaimAccount *a, GaimBuddy *b) | |
347 { | |
348 return "rendezvous"; | |
349 } | |
350 | |
9965 | 351 static void rendezvous_prpl_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) |
8487 | 352 { |
353 if (GAIM_BUDDY_IS_ONLINE(b)) { | |
354 if (b->uc & UC_UNAVAILABLE) | |
355 *se = "away"; | |
356 } else { | |
357 *se = "offline"; | |
358 } | |
359 } | |
360 | |
361 static gchar *rendezvous_prpl_status_text(GaimBuddy *b) | |
362 { | |
363 GaimConnection *gc = b->account->gc; | |
364 RendezvousData *rd = gc->proto_data; | |
365 RendezvousBuddy *rb; | |
366 gchar *ret; | |
367 | |
368 rb = g_hash_table_lookup(rd->buddies, b->name); | |
369 if ((rb == NULL) || (rb->msg == NULL)) | |
370 return NULL; | |
371 | |
372 ret = g_strdup(rb->msg); | |
373 | |
374 return ret; | |
375 } | |
376 | |
377 static gchar *rendezvous_prpl_tooltip_text(GaimBuddy *b) | |
378 { | |
379 GaimConnection *gc = b->account->gc; | |
380 RendezvousData *rd = gc->proto_data; | |
381 RendezvousBuddy *rb; | |
382 GString *ret; | |
383 | |
384 rb = g_hash_table_lookup(rd->buddies, b->name); | |
385 if (rb == NULL) | |
386 return NULL; | |
387 | |
388 ret = g_string_new(""); | |
389 | |
390 if (rb->aim != NULL) | |
8591 | 391 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("AIM Screen name"), rb->aim); |
8487 | 392 |
393 if (rb->msg != NULL) { | |
394 if (rb->status == UC_UNAVAILABLE) | |
8591 | 395 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Away"), rb->msg); |
8487 | 396 else |
8591 | 397 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Available"), rb->msg); |
8487 | 398 } |
399 | |
400 return g_string_free(ret, FALSE); | |
401 } | |
402 | |
403 /****************************/ | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8721
diff
changeset
|
404 /* Connection Functions */ |
8487 | 405 /****************************/ |
406 static void rendezvous_callback(gpointer data, gint source, GaimInputCondition condition) | |
407 { | |
408 GaimConnection *gc = data; | |
409 RendezvousData *rd = gc->proto_data; | |
410 DNSPacket *dns; | |
8806 | 411 GSList *cur; |
8487 | 412 |
413 gaim_debug_misc("rendezvous", "Received rendezvous datagram\n"); | |
414 | |
415 dns = mdns_read(rd->fd); | |
416 if (dns == NULL) | |
417 return; | |
418 | |
419 /* Handle the DNS packet */ | |
8806 | 420 for (cur = dns->answers; cur != NULL; cur = cur->next) |
421 rendezvous_handle_rr(gc, cur->data); | |
422 for (cur = dns->authority; cur != NULL; cur = cur->next) | |
423 rendezvous_handle_rr(gc, cur->data); | |
424 for (cur = dns->additional; cur != NULL; cur = cur->next) | |
425 rendezvous_handle_rr(gc, cur->data); | |
8487 | 426 |
427 mdns_free(dns); | |
428 } | |
429 | |
8629 | 430 static void rendezvous_add_to_txt(RendezvousData *rd, const char *name, const char *value) |
431 { | |
8631 | 432 ResourceRecordRDataTXTNode *node; |
433 node = g_malloc(sizeof(ResourceRecordRDataTXTNode)); | |
8629 | 434 node->name = g_strdup(name); |
435 node->value = value != NULL ? g_strdup(value) : NULL; | |
436 rd->mytxtdata = g_slist_append(rd->mytxtdata, node); | |
437 } | |
438 | |
9416 | 439 static guchar *rendezvous_read_icon_data(const char *filename, unsigned short *length) |
440 { | |
441 struct stat st; | |
442 FILE *file; | |
443 guchar *data; | |
444 | |
445 *length = 0; | |
446 | |
447 g_return_val_if_fail(filename != NULL, NULL); | |
448 | |
449 if (stat(filename, &st)) | |
450 return NULL; | |
451 | |
452 if (!(file = fopen(filename, "rb"))) | |
453 return NULL; | |
454 | |
455 *length = st.st_size; | |
456 data = g_malloc(*length); | |
457 fread(data, 1, *length, file); | |
458 fclose(file); | |
459 | |
460 return data; | |
461 } | |
462 | |
463 static void rendezvous_add_to_txt_iconhash(RendezvousData *rd, const char *iconfile) | |
464 { | |
465 guchar *icondata; | |
466 unsigned short iconlength; | |
467 unsigned char hash[20]; | |
468 gchar *base16; | |
469 | |
470 g_return_if_fail(rd != NULL); | |
471 | |
472 if (iconfile == NULL) | |
473 return; | |
474 | |
475 icondata = rendezvous_read_icon_data(iconfile, &iconlength); | |
476 shaBlock((unsigned char *)icondata, iconlength, hash); | |
477 g_free(icondata); | |
478 | |
479 base16 = gaim_base16_encode(hash, 20); | |
480 rendezvous_add_to_txt(rd, "phsh", base16); | |
481 g_free(base16); | |
482 } | |
483 | |
8636 | 484 static void rendezvous_send_icon(GaimConnection *gc) |
485 { | |
486 RendezvousData *rd = gc->proto_data; | |
487 GaimAccount *account = gaim_connection_get_account(gc); | |
488 const char *iconfile = gaim_account_get_buddy_icon(account); | |
489 unsigned char *rdata; | |
490 unsigned short rdlength; | |
491 gchar *myname; | |
492 | |
493 if (iconfile == NULL) | |
494 return; | |
495 | |
9416 | 496 rdata = rendezvous_read_icon_data(iconfile, &rdlength); |
8636 | 497 |
498 myname = g_strdup_printf("%s._presence._tcp.local", gaim_account_get_username(account)); | |
499 mdns_advertise_null(rd->fd, myname, rdata, rdlength); | |
500 g_free(myname); | |
8695 | 501 |
502 g_free(rdata); | |
8636 | 503 } |
504 | |
8629 | 505 static void rendezvous_send_online(GaimConnection *gc) |
506 { | |
507 RendezvousData *rd = gc->proto_data; | |
508 GaimAccount *account = gaim_connection_get_account(gc); | |
8636 | 509 const gchar *me; |
510 gchar *myname, *mycomp; | |
8840 | 511 unsigned char myip[4]; |
8629 | 512 |
8631 | 513 me = gaim_account_get_username(account); |
514 myname = g_strdup_printf("%s._presence._tcp.local", me); | |
515 mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1); | |
8840 | 516 /* myip = gaim_network_ip_atoi(gaim_network_get_local_system_ip(-1)); */ |
517 myip[0] = 192; | |
518 myip[1] = 168; | |
519 myip[2] = 1; | |
520 myip[3] = 41; | |
8631 | 521 |
8834 | 522 mdns_advertise_a(rd->fd, mycomp, myip); |
8631 | 523 mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname); |
524 mdns_advertise_srv(rd->fd, myname, 5298, mycomp); | |
8629 | 525 |
526 rendezvous_add_to_txt(rd, "txtvers", "1"); | |
527 rendezvous_add_to_txt(rd, "status", "avail"); | |
8631 | 528 /* rendezvous_add_to_txt(rd, "vc", "A!"); */ |
9416 | 529 rendezvous_add_to_txt_iconhash(rd, gaim_account_get_buddy_icon(account)); |
8629 | 530 rendezvous_add_to_txt(rd, "1st", gaim_account_get_string(account, "first", "Gaim")); |
8631 | 531 if (gaim_account_get_bool(account, "shareaim", FALSE)) { |
532 GList *l; | |
533 GaimAccount *cur; | |
534 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
535 cur = (GaimAccount *)l->data; | |
536 if (!strcmp(gaim_account_get_protocol_id(cur), "prpl-oscar")) { | |
8634 | 537 /* XXX - Should the name be normalized? */ |
8631 | 538 rendezvous_add_to_txt(rd, "AIM", gaim_account_get_username(cur)); |
539 break; | |
540 } | |
541 } | |
542 } | |
8629 | 543 rendezvous_add_to_txt(rd, "version", "1"); |
8631 | 544 rendezvous_add_to_txt(rd, "msg", "Groovin'"); |
8629 | 545 rendezvous_add_to_txt(rd, "port.p2pj", "5298"); |
546 rendezvous_add_to_txt(rd, "last", gaim_account_get_string(account, "last", _("User"))); | |
8631 | 547 mdns_advertise_txt(rd->fd, myname, rd->mytxtdata); |
8629 | 548 |
8636 | 549 rendezvous_send_icon(gc); |
550 | |
8631 | 551 g_free(myname); |
552 g_free(mycomp); | |
8629 | 553 } |
554 | |
8487 | 555 static void rendezvous_prpl_login(GaimAccount *account) |
556 { | |
557 GaimConnection *gc = gaim_account_get_connection(account); | |
558 RendezvousData *rd; | |
559 | |
560 rd = g_new0(RendezvousData, 1); | |
561 rd->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, rendezvous_buddy_free); | |
562 gc->proto_data = rd; | |
563 | |
564 gaim_connection_update_progress(gc, _("Preparing Buddy List"), 0, RENDEZVOUS_CONNECT_STEPS); | |
565 rendezvous_removeallfromlocal(gc); | |
566 | |
567 gaim_connection_update_progress(gc, _("Connecting"), 1, RENDEZVOUS_CONNECT_STEPS); | |
8834 | 568 rd->fd = mdns_socket_establish(); |
8487 | 569 if (rd->fd == -1) { |
570 gaim_connection_error(gc, _("Unable to login to rendezvous")); | |
571 return; | |
572 } | |
573 | |
574 gc->inpa = gaim_input_add(rd->fd, GAIM_INPUT_READ, rendezvous_callback, gc); | |
575 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
576 | |
8636 | 577 mdns_query(rd->fd, "_presence._tcp.local", RENDEZVOUS_RRTYPE_ALL); |
8629 | 578 rendezvous_send_online(gc); |
8487 | 579 } |
580 | |
581 static void rendezvous_prpl_close(GaimConnection *gc) | |
582 { | |
583 RendezvousData *rd = (RendezvousData *)gc->proto_data; | |
8631 | 584 ResourceRecordRDataTXTNode *node; |
8487 | 585 |
586 if (gc->inpa) | |
587 gaim_input_remove(gc->inpa); | |
588 | |
589 rendezvous_removeallfromlocal(gc); | |
590 | |
591 if (!rd) | |
592 return; | |
593 | |
8834 | 594 mdns_socket_close(rd->fd); |
8487 | 595 |
596 g_hash_table_destroy(rd->buddies); | |
597 | |
8629 | 598 while (rd->mytxtdata != NULL) { |
599 node = rd->mytxtdata->data; | |
600 rd->mytxtdata = g_slist_remove(rd->mytxtdata, node); | |
601 g_free(node->name); | |
602 g_free(node->value); | |
603 g_free(node); | |
604 } | |
605 | |
8487 | 606 g_free(rd); |
607 } | |
608 | |
609 static int rendezvous_prpl_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags) | |
610 { | |
611 gaim_debug_info("rendezvous", "Sending IM\n"); | |
612 | |
613 return 1; | |
614 } | |
615 | |
616 static GaimPlugin *my_protocol = NULL; | |
617 | |
8842 | 618 static GaimPluginProtocolInfo prpl_info; |
8487 | 619 |
620 static GaimPluginInfo info = | |
621 { | |
9954 | 622 GAIM_PLUGIN_MAGIC, |
623 GAIM_MAJOR_VERSION, | |
624 GAIM_MINOR_VERSION, | |
8487 | 625 GAIM_PLUGIN_PROTOCOL, /**< type */ |
626 NULL, /**< ui_requirement */ | |
627 0, /**< flags */ | |
628 NULL, /**< dependencies */ | |
629 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
630 | |
631 "prpl-rendezvous", /**< id */ | |
632 "Rendezvous", /**< name */ | |
633 VERSION, /**< version */ | |
634 /** summary */ | |
635 N_("Rendezvous Protocol Plugin"), | |
636 /** description */ | |
637 N_("Rendezvous Protocol Plugin"), | |
638 NULL, /**< author */ | |
639 GAIM_WEBSITE, /**< homepage */ | |
640 | |
641 NULL, /**< load */ | |
642 NULL, /**< unload */ | |
643 NULL, /**< destroy */ | |
644 | |
645 NULL, /**< ui_info */ | |
8993 | 646 &prpl_info, /**< extra_info */ |
647 NULL, | |
648 NULL | |
8487 | 649 }; |
650 | |
651 static void init_plugin(GaimPlugin *plugin) | |
652 { | |
653 GaimAccountUserSplit *split; | |
654 GaimAccountOption *option; | |
8631 | 655 char hostname[255]; |
656 | |
9318 | 657 prpl_info.options = OPT_PROTO_NO_PASSWORD; |
658 prpl_info.icon_spec.format = "jpeg"; | |
659 prpl_info.icon_spec.min_width = 0; | |
660 prpl_info.icon_spec.min_height = 0; | |
661 prpl_info.icon_spec.max_width = 0; | |
662 prpl_info.icon_spec.max_height = 0; | |
9394 | 663 prpl_info.icon_spec.scale_rules = 0; |
9318 | 664 prpl_info.list_icon = rendezvous_prpl_list_icon; |
665 prpl_info.list_emblems = rendezvous_prpl_list_emblems; | |
666 prpl_info.status_text = rendezvous_prpl_status_text; | |
667 prpl_info.tooltip_text = rendezvous_prpl_tooltip_text; | |
668 prpl_info.login = rendezvous_prpl_login; | |
669 prpl_info.close = rendezvous_prpl_close; | |
670 prpl_info.send_im = rendezvous_prpl_send_im; | |
8842 | 671 |
8631 | 672 if (gethostname(hostname, 255) != 0) { |
673 gaim_debug_warning("rendezvous", "Error %d when getting host name. Using \"localhost.\"\n", errno); | |
674 strcpy(hostname, "localhost"); | |
675 } | |
8487 | 676 |
677 /* Try to avoid making this configurable... */ | |
8842 | 678 split = gaim_account_user_split_new(_("Host name"), hostname, '@'); |
8487 | 679 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
680 | |
8842 | 681 option = gaim_account_option_string_new(_("First name"), "first", "Gaim"); |
8487 | 682 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
683 option); | |
684 | |
8842 | 685 option = gaim_account_option_string_new(_("Last name"), "last", _("User")); |
8487 | 686 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
687 option); | |
688 | |
8631 | 689 option = gaim_account_option_bool_new(_("Share AIM screen name"), "shareaim", FALSE); |
8487 | 690 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
691 option); | |
692 | |
693 my_protocol = plugin; | |
694 } | |
695 | |
696 GAIM_INIT_PLUGIN(rendezvous, init_plugin, info); |