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