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