Mercurial > pidgin
annotate src/protocols/rendezvous/rendezvous.c @ 8834:beb7be215db3
[gaim-migrate @ 9598]
I removed account->ip because it isn't used anywhere and I think it's dumb.
Also added handling for a and aaaa records to rendezvous. Gaim peeps
show up in iChat rendezvous lists now. There are still problems.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Wed, 28 Apr 2004 00:48:21 +0000 |
| parents | 8212661dc3cc |
| children | 518455386538 |
| 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 */ |
| 8612 | 148 |
| 149 /* | |
| 150 * XXX - Instead of removing immediately, wait 10 seconds and THEN remove | |
| 151 * them. If you do it immediately you don't see the door close icon. | |
| 152 */ | |
| 8487 | 153 } |
| 154 | |
| 155 static void rendezvous_removeallfromlocal(GaimConnection *gc) | |
| 156 { | |
| 157 GaimAccount *account = gaim_connection_get_account(gc); | |
| 158 GaimBuddyList *blist; | |
| 159 GaimBlistNode *gnode, *cnode, *bnode; | |
| 160 GaimBuddy *b; | |
| 161 | |
| 162 /* Go through and remove all buddies that belong to this account */ | |
| 163 if ((blist = gaim_get_blist()) != NULL) { | |
| 164 for (gnode = blist->root; gnode; gnode = gnode->next) { | |
| 165 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 166 continue; | |
| 167 for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
| 168 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
| 169 continue; | |
| 170 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 171 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 172 continue; | |
| 173 b = (GaimBuddy *)bnode; | |
| 174 if (b->account != account) | |
| 175 continue; | |
| 176 serv_got_update(gc, b->name, 0, 0, 0, 0, 0); | |
| 177 gaim_blist_remove_buddy(b); | |
| 178 } | |
| 179 } | |
| 180 } | |
| 181 } | |
| 182 } | |
| 183 | |
| 8834 | 184 static void rendezvous_handle_rr_a(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
| 185 { | |
| 186 RendezvousData *rd = gc->proto_data; | |
| 187 RendezvousBuddy *rb; | |
| 188 ResourceRecordRDataSRV *rdata; | |
| 189 | |
| 190 rdata = rr->rdata; | |
| 191 | |
| 192 rb = g_hash_table_lookup(rd->buddies, name); | |
| 193 if (rb == NULL) { | |
| 194 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
| 195 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
| 196 } | |
| 197 | |
| 198 memcpy(rb->ip, rdata, 4); | |
| 199 } | |
| 200 | |
| 8487 | 201 static void rendezvous_handle_rr_txt(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
| 202 { | |
| 203 RendezvousData *rd = gc->proto_data; | |
| 204 RendezvousBuddy *rb; | |
| 8806 | 205 GSList *rdata; |
| 206 ResourceRecordRDataTXTNode *node1, *node2; | |
| 8487 | 207 |
| 8594 | 208 rdata = rr->rdata; |
| 209 | |
| 210 /* Don't do a damn thing if the version is greater than 1 */ | |
| 8806 | 211 node1 = mdns_txt_find(rdata, "version"); |
| 212 if ((node1 == NULL) || (node1->value == NULL) || (strcmp(node1->value, "1"))) | |
| 8594 | 213 return; |
| 214 | |
| 8487 | 215 rb = g_hash_table_lookup(rd->buddies, name); |
| 216 if (rb == NULL) { | |
| 217 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
| 218 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
| 219 } | |
| 220 | |
| 8806 | 221 node1 = mdns_txt_find(rdata, "1st"); |
| 222 node2 = mdns_txt_find(rdata, "last"); | |
| 8487 | 223 g_free(rb->firstandlast); |
| 224 rb->firstandlast = g_strdup_printf("%s%s%s", | |
| 8806 | 225 (node1 && node1->value ? node1->value : ""), |
| 226 (node1 && node1->value && node2 && node2->value ? " " : ""), | |
| 227 (node2 && node2->value ? node2->value : "")); | |
| 8487 | 228 serv_got_alias(gc, name, rb->firstandlast); |
| 229 | |
| 8806 | 230 node1 = mdns_txt_find(rdata, "aim"); |
| 231 if ((node1 != NULL) && (node1->value != NULL)) { | |
| 8487 | 232 g_free(rb->aim); |
| 8806 | 233 rb->aim = g_strdup(node1->value); |
| 8487 | 234 } |
| 235 | |
| 8594 | 236 /* |
| 237 * We only want to use this port as a back-up. Ideally the port | |
| 238 * is specified in a separate, SRV resource record. | |
| 239 */ | |
| 240 if (rb->p2pjport == 0) { | |
| 8806 | 241 node1 = mdns_txt_find(rdata, "port.p2pj"); |
| 242 if ((node1 != NULL) && (node1->value)) | |
| 243 rb->p2pjport = atoi(node1->value); | |
| 8594 | 244 } |
| 8487 | 245 |
| 8806 | 246 node1 = mdns_txt_find(rdata, "status");; |
| 247 if ((node1 != NULL) && (node1->value != NULL)) { | |
| 248 if (!strcmp(node1->value, "avail")) { | |
| 8487 | 249 /* Available */ |
| 250 rb->status = 0; | |
| 8806 | 251 } else if (!strcmp(node1->value, "away")) { |
| 8487 | 252 /* Idle */ |
| 8806 | 253 node2 = mdns_txt_find(rdata, "away"); |
| 254 if ((node2 != NULL) && (node2->value)) { | |
| 255 rb->idle = atoi(node2->value); | |
| 256 gaim_debug_error("XXX", "User has been idle since %d\n", rb->idle); | |
| 257 } | |
| 8487 | 258 rb->status = UC_IDLE; |
| 8806 | 259 } else if (!strcmp(node1->value, "dnd")) { |
| 8487 | 260 /* Away */ |
| 261 rb->status = UC_UNAVAILABLE; | |
| 262 } | |
| 263 serv_got_update(gc, name, 1, 0, 0, 0, rb->status); | |
| 264 } | |
| 265 | |
| 8806 | 266 node1 = mdns_txt_find(rdata, "msg"); |
| 267 if ((node1 != NULL) && (node1->value != NULL)) { | |
| 8487 | 268 g_free(rb->msg); |
| 8806 | 269 rb->msg = g_strdup(node1->value); |
| 8487 | 270 } |
| 8594 | 271 } |
| 8546 | 272 |
| 8594 | 273 static void rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name) |
| 274 { | |
| 275 RendezvousData *rd = gc->proto_data; | |
| 276 RendezvousBuddy *rb; | |
| 8806 | 277 ResourceRecordRDataSRV *rdata; |
| 8594 | 278 |
| 279 rdata = rr->rdata; | |
| 280 | |
| 281 rb = g_hash_table_lookup(rd->buddies, name); | |
| 282 if (rb == NULL) { | |
| 283 rb = g_malloc0(sizeof(RendezvousBuddy)); | |
| 284 g_hash_table_insert(rd->buddies, g_strdup(name), rb); | |
| 285 } | |
| 286 | |
| 287 rb->p2pjport = rdata->port; | |
| 8487 | 288 } |
| 289 | |
| 290 /* | |
| 291 * Parse a resource record and do stuff if we need to. | |
| 292 */ | |
| 293 static void rendezvous_handle_rr(GaimConnection *gc, ResourceRecord *rr) | |
| 294 { | |
| 8636 | 295 RendezvousData *rd = gc->proto_data; |
| 8487 | 296 gchar *name; |
| 297 | |
| 8594 | 298 gaim_debug_misc("rendezvous", "Parsing resource record with domain name %s\n", rr->name); |
| 299 | |
| 8834 | 300 switch (rr->type) { |
| 301 case RENDEZVOUS_RRTYPE_A: { | |
| 302 name = rendezvous_extract_name(rr->name); | |
| 303 if (name != NULL) { | |
| 304 rendezvous_handle_rr_a(gc, rr, name); | |
| 305 g_free(name); | |
| 306 } | |
| 307 } break; | |
| 8487 | 308 |
| 309 case RENDEZVOUS_RRTYPE_NULL: { | |
| 8834 | 310 name = rendezvous_extract_name(rr->name); |
| 311 if (name != NULL) { | |
| 8487 | 312 if (rr->rdlength > 0) { |
| 313 /* Data is a buddy icon */ | |
| 314 gaim_buddy_icons_set_for_user(gaim_connection_get_account(gc), name, rr->rdata, rr->rdlength); | |
| 315 } | |
| 316 | |
| 317 g_free(name); | |
| 318 } | |
| 319 } break; | |
| 320 | |
| 321 case RENDEZVOUS_RRTYPE_PTR: { | |
| 322 gchar *rdata = rr->rdata; | |
| 8834 | 323 |
| 324 name = rendezvous_extract_name(rdata); | |
| 325 if (name != NULL) { | |
| 8636 | 326 if (rr->ttl > 0) { |
| 327 /* Add them to our buddy list and request their icon */ | |
| 8487 | 328 rendezvous_addtolocal(gc, name, "Rendezvous"); |
| 8636 | 329 mdns_query(rd->fd, rdata, RENDEZVOUS_RRTYPE_NULL); |
| 330 } else { | |
| 331 /* Remove them from our buddy list */ | |
| 8487 | 332 rendezvous_removefromlocal(gc, name, "Rendezvous"); |
| 8636 | 333 } |
| 8487 | 334 g_free(name); |
| 335 } | |
| 336 } break; | |
| 337 | |
| 338 case RENDEZVOUS_RRTYPE_TXT: { | |
| 8834 | 339 name = rendezvous_extract_name(rr->name); |
| 340 if (name != NULL) { | |
| 8487 | 341 rendezvous_handle_rr_txt(gc, rr, name); |
| 342 g_free(name); | |
| 343 } | |
| 344 } break; | |
| 8594 | 345 |
| 346 case RENDEZVOUS_RRTYPE_SRV: { | |
| 8834 | 347 name = rendezvous_extract_name(rr->name); |
| 348 if (name != NULL) { | |
| 8594 | 349 rendezvous_handle_rr_srv(gc, rr, name); |
| 350 g_free(name); | |
| 351 } | |
| 352 } break; | |
| 8487 | 353 } |
| 354 } | |
| 355 | |
| 356 /****************************/ | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8721
diff
changeset
|
357 /* Icon and Emblem Functions */ |
| 8487 | 358 /****************************/ |
| 359 static const char* rendezvous_prpl_list_icon(GaimAccount *a, GaimBuddy *b) | |
| 360 { | |
| 361 return "rendezvous"; | |
| 362 } | |
| 363 | |
| 364 static void rendezvous_prpl_list_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) | |
| 365 { | |
| 366 if (GAIM_BUDDY_IS_ONLINE(b)) { | |
| 367 if (b->uc & UC_UNAVAILABLE) | |
| 368 *se = "away"; | |
| 369 } else { | |
| 370 *se = "offline"; | |
| 371 } | |
| 372 } | |
| 373 | |
| 374 static gchar *rendezvous_prpl_status_text(GaimBuddy *b) | |
| 375 { | |
| 376 GaimConnection *gc = b->account->gc; | |
| 377 RendezvousData *rd = gc->proto_data; | |
| 378 RendezvousBuddy *rb; | |
| 379 gchar *ret; | |
| 380 | |
| 381 rb = g_hash_table_lookup(rd->buddies, b->name); | |
| 382 if ((rb == NULL) || (rb->msg == NULL)) | |
| 383 return NULL; | |
| 384 | |
| 385 ret = g_strdup(rb->msg); | |
| 386 | |
| 387 return ret; | |
| 388 } | |
| 389 | |
| 390 static gchar *rendezvous_prpl_tooltip_text(GaimBuddy *b) | |
| 391 { | |
| 392 GaimConnection *gc = b->account->gc; | |
| 393 RendezvousData *rd = gc->proto_data; | |
| 394 RendezvousBuddy *rb; | |
| 395 GString *ret; | |
| 396 | |
| 397 rb = g_hash_table_lookup(rd->buddies, b->name); | |
| 398 if (rb == NULL) | |
| 399 return NULL; | |
| 400 | |
| 401 ret = g_string_new(""); | |
| 402 | |
| 403 if (rb->aim != NULL) | |
| 8591 | 404 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("AIM Screen name"), rb->aim); |
| 8487 | 405 |
| 406 if (rb->msg != NULL) { | |
| 407 if (rb->status == UC_UNAVAILABLE) | |
| 8591 | 408 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Away"), rb->msg); |
| 8487 | 409 else |
| 8591 | 410 g_string_append_printf(ret, "\n<b>%s</b>: %s", _("Available"), rb->msg); |
| 8487 | 411 } |
| 412 | |
| 413 return g_string_free(ret, FALSE); | |
| 414 } | |
| 415 | |
| 416 /****************************/ | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8721
diff
changeset
|
417 /* Connection Functions */ |
| 8487 | 418 /****************************/ |
| 419 static void rendezvous_callback(gpointer data, gint source, GaimInputCondition condition) | |
| 420 { | |
| 421 GaimConnection *gc = data; | |
| 422 RendezvousData *rd = gc->proto_data; | |
| 423 DNSPacket *dns; | |
| 8806 | 424 GSList *cur; |
| 8487 | 425 |
| 426 gaim_debug_misc("rendezvous", "Received rendezvous datagram\n"); | |
| 427 | |
| 428 dns = mdns_read(rd->fd); | |
| 429 if (dns == NULL) | |
| 430 return; | |
| 431 | |
| 432 /* Handle the DNS packet */ | |
| 8806 | 433 for (cur = dns->answers; cur != NULL; cur = cur->next) |
| 434 rendezvous_handle_rr(gc, cur->data); | |
| 435 for (cur = dns->authority; cur != NULL; cur = cur->next) | |
| 436 rendezvous_handle_rr(gc, cur->data); | |
| 437 for (cur = dns->additional; cur != NULL; cur = cur->next) | |
| 438 rendezvous_handle_rr(gc, cur->data); | |
| 8487 | 439 |
| 440 mdns_free(dns); | |
| 441 } | |
| 442 | |
| 8629 | 443 static void rendezvous_add_to_txt(RendezvousData *rd, const char *name, const char *value) |
| 444 { | |
| 8631 | 445 ResourceRecordRDataTXTNode *node; |
| 446 node = g_malloc(sizeof(ResourceRecordRDataTXTNode)); | |
| 8629 | 447 node->name = g_strdup(name); |
| 448 node->value = value != NULL ? g_strdup(value) : NULL; | |
| 449 rd->mytxtdata = g_slist_append(rd->mytxtdata, node); | |
| 450 } | |
| 451 | |
| 8636 | 452 static void rendezvous_send_icon(GaimConnection *gc) |
| 453 { | |
| 454 RendezvousData *rd = gc->proto_data; | |
| 455 GaimAccount *account = gaim_connection_get_account(gc); | |
| 456 const char *iconfile = gaim_account_get_buddy_icon(account); | |
| 457 struct stat st; | |
| 458 FILE *file; | |
| 459 unsigned char *rdata; | |
| 460 unsigned short rdlength; | |
| 461 gchar *myname; | |
| 462 | |
| 463 if (iconfile == NULL) | |
| 464 return; | |
| 465 | |
| 466 if (stat(iconfile, &st)) | |
| 467 return; | |
| 468 | |
| 469 if (!(file = fopen(iconfile, "rb"))) | |
| 470 return; | |
| 471 | |
| 472 rdlength = st.st_size; | |
| 473 rdata = g_malloc(rdlength); | |
| 474 fread(rdata, 1, rdlength, file); | |
| 475 fclose(file); | |
| 476 | |
| 477 myname = g_strdup_printf("%s._presence._tcp.local", gaim_account_get_username(account)); | |
| 478 mdns_advertise_null(rd->fd, myname, rdata, rdlength); | |
| 479 g_free(myname); | |
| 8695 | 480 |
| 481 g_free(rdata); | |
| 8636 | 482 } |
| 483 | |
| 8834 | 484 static int *rendezvous_get_ip_as_int_array(int fd) |
| 485 { | |
| 486 static int ret[4]; | |
| 487 const char *ip, *nexttoken; | |
| 488 int i = 0; | |
| 489 | |
| 490 ip = gaim_network_get_local_system_ip(fd); | |
| 491 nexttoken = strtok((char *)ip, "."); | |
| 492 while (nexttoken && i < 4) { | |
| 493 ret[i] = atoi(nexttoken); | |
| 494 nexttoken = strtok(NULL, "."); | |
| 495 } | |
| 496 | |
| 497 return ret; | |
| 498 } | |
| 499 | |
| 8629 | 500 static void rendezvous_send_online(GaimConnection *gc) |
| 501 { | |
| 502 RendezvousData *rd = gc->proto_data; | |
| 503 GaimAccount *account = gaim_connection_get_account(gc); | |
| 8636 | 504 const gchar *me; |
| 505 gchar *myname, *mycomp; | |
| 8834 | 506 unsigned char *myip; |
| 8629 | 507 |
| 8631 | 508 me = gaim_account_get_username(account); |
| 509 myname = g_strdup_printf("%s._presence._tcp.local", me); | |
| 510 mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1); | |
| 8834 | 511 myip = rendezvous_get_ip_as_int_array(rd->fd); |
| 8631 | 512 |
| 8834 | 513 mdns_advertise_a(rd->fd, mycomp, myip); |
| 8631 | 514 mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname); |
| 515 mdns_advertise_srv(rd->fd, myname, 5298, mycomp); | |
| 8629 | 516 |
| 517 rendezvous_add_to_txt(rd, "txtvers", "1"); | |
| 518 rendezvous_add_to_txt(rd, "status", "avail"); | |
| 8631 | 519 /* rendezvous_add_to_txt(rd, "vc", "A!"); */ |
| 520 /* rendezvous_add_to_txt(rd, "phsh", "96f15dec163cf4a8cfa0cf08109cc9766f7bd5a0"); */ | |
| 8629 | 521 rendezvous_add_to_txt(rd, "1st", gaim_account_get_string(account, "first", "Gaim")); |
| 8631 | 522 if (gaim_account_get_bool(account, "shareaim", FALSE)) { |
| 523 GList *l; | |
| 524 GaimAccount *cur; | |
| 525 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
| 526 cur = (GaimAccount *)l->data; | |
| 527 if (!strcmp(gaim_account_get_protocol_id(cur), "prpl-oscar")) { | |
| 8634 | 528 /* XXX - Should the name be normalized? */ |
| 8631 | 529 rendezvous_add_to_txt(rd, "AIM", gaim_account_get_username(cur)); |
| 530 break; | |
| 531 } | |
| 532 } | |
| 533 } | |
| 8629 | 534 rendezvous_add_to_txt(rd, "version", "1"); |
| 8631 | 535 rendezvous_add_to_txt(rd, "msg", "Groovin'"); |
| 8629 | 536 rendezvous_add_to_txt(rd, "port.p2pj", "5298"); |
| 537 rendezvous_add_to_txt(rd, "last", gaim_account_get_string(account, "last", _("User"))); | |
| 8631 | 538 mdns_advertise_txt(rd->fd, myname, rd->mytxtdata); |
| 8629 | 539 |
| 8636 | 540 rendezvous_send_icon(gc); |
| 541 | |
| 8631 | 542 g_free(myname); |
| 543 g_free(mycomp); | |
| 8629 | 544 } |
| 545 | |
| 8487 | 546 static void rendezvous_prpl_login(GaimAccount *account) |
| 547 { | |
| 548 GaimConnection *gc = gaim_account_get_connection(account); | |
| 549 RendezvousData *rd; | |
| 550 | |
| 551 rd = g_new0(RendezvousData, 1); | |
| 552 rd->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, rendezvous_buddy_free); | |
| 553 gc->proto_data = rd; | |
| 554 | |
| 555 gaim_connection_update_progress(gc, _("Preparing Buddy List"), 0, RENDEZVOUS_CONNECT_STEPS); | |
| 556 rendezvous_removeallfromlocal(gc); | |
| 557 | |
| 558 gaim_connection_update_progress(gc, _("Connecting"), 1, RENDEZVOUS_CONNECT_STEPS); | |
| 8834 | 559 rd->fd = mdns_socket_establish(); |
| 8487 | 560 if (rd->fd == -1) { |
| 561 gaim_connection_error(gc, _("Unable to login to rendezvous")); | |
| 562 return; | |
| 563 } | |
| 564 | |
| 565 gc->inpa = gaim_input_add(rd->fd, GAIM_INPUT_READ, rendezvous_callback, gc); | |
| 566 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
| 567 | |
| 8636 | 568 mdns_query(rd->fd, "_presence._tcp.local", RENDEZVOUS_RRTYPE_ALL); |
| 8629 | 569 rendezvous_send_online(gc); |
| 8487 | 570 } |
| 571 | |
| 572 static void rendezvous_prpl_close(GaimConnection *gc) | |
| 573 { | |
| 574 RendezvousData *rd = (RendezvousData *)gc->proto_data; | |
| 8631 | 575 ResourceRecordRDataTXTNode *node; |
| 8487 | 576 |
| 577 if (gc->inpa) | |
| 578 gaim_input_remove(gc->inpa); | |
| 579 | |
| 580 rendezvous_removeallfromlocal(gc); | |
| 581 | |
| 582 if (!rd) | |
| 583 return; | |
| 584 | |
| 8834 | 585 mdns_socket_close(rd->fd); |
| 8487 | 586 |
| 587 g_hash_table_destroy(rd->buddies); | |
| 588 | |
| 8629 | 589 while (rd->mytxtdata != NULL) { |
| 590 node = rd->mytxtdata->data; | |
| 591 rd->mytxtdata = g_slist_remove(rd->mytxtdata, node); | |
| 592 g_free(node->name); | |
| 593 g_free(node->value); | |
| 594 g_free(node); | |
| 595 } | |
| 596 | |
| 8487 | 597 g_free(rd); |
| 598 } | |
| 599 | |
| 600 static int rendezvous_prpl_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags) | |
| 601 { | |
| 602 gaim_debug_info("rendezvous", "Sending IM\n"); | |
| 603 | |
| 604 return 1; | |
| 605 } | |
| 606 | |
| 8589 | 607 static void rendezvous_prpl_set_away(GaimConnection *gc, const char *state, const char *text) |
| 8487 | 608 { |
| 609 gaim_debug_error("rendezvous", "Set away, state=%s, text=%s\n", state, text); | |
| 610 } | |
| 611 | |
| 612 static GaimPlugin *my_protocol = NULL; | |
| 613 | |
| 614 static GaimPluginProtocolInfo prpl_info = | |
| 615 { | |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
616 GAIM_PRPL_API_VERSION, |
| 8636 | 617 OPT_PROTO_NO_PASSWORD | OPT_PROTO_BUDDY_ICON, |
| 8487 | 618 NULL, |
| 619 NULL, | |
| 620 rendezvous_prpl_list_icon, | |
| 621 rendezvous_prpl_list_emblems, | |
| 622 rendezvous_prpl_status_text, | |
| 623 rendezvous_prpl_tooltip_text, | |
| 624 NULL, | |
| 625 NULL, | |
| 626 NULL, | |
| 627 NULL, | |
| 628 rendezvous_prpl_login, | |
| 629 rendezvous_prpl_close, | |
| 630 rendezvous_prpl_send_im, | |
| 631 NULL, | |
| 632 NULL, | |
| 633 NULL, | |
| 8589 | 634 rendezvous_prpl_set_away, |
| 8487 | 635 NULL, |
| 636 NULL, | |
| 637 NULL, | |
| 638 NULL, | |
| 639 NULL, | |
| 640 NULL, | |
| 641 NULL, | |
| 642 NULL, | |
| 643 NULL, | |
| 644 NULL, | |
| 645 NULL, | |
| 646 NULL, | |
| 647 NULL, | |
| 648 NULL, | |
| 649 NULL, | |
| 650 NULL, | |
| 651 NULL, | |
| 652 NULL, | |
| 653 NULL, | |
| 654 NULL, | |
| 655 NULL, | |
| 656 NULL, | |
| 657 NULL, | |
| 658 NULL, | |
| 659 NULL, | |
| 660 NULL, | |
| 661 NULL, | |
| 662 NULL, | |
| 663 NULL, | |
| 664 NULL, | |
| 8586 | 665 NULL, |
| 8589 | 666 NULL |
| 8487 | 667 }; |
| 668 | |
| 669 static GaimPluginInfo info = | |
| 670 { | |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
671 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
| 8487 | 672 GAIM_PLUGIN_PROTOCOL, /**< type */ |
| 673 NULL, /**< ui_requirement */ | |
| 674 0, /**< flags */ | |
| 675 NULL, /**< dependencies */ | |
| 676 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 677 | |
| 678 "prpl-rendezvous", /**< id */ | |
| 679 "Rendezvous", /**< name */ | |
| 680 VERSION, /**< version */ | |
| 681 /** summary */ | |
| 682 N_("Rendezvous Protocol Plugin"), | |
| 683 /** description */ | |
| 684 N_("Rendezvous Protocol Plugin"), | |
| 685 NULL, /**< author */ | |
| 686 GAIM_WEBSITE, /**< homepage */ | |
| 687 | |
| 688 NULL, /**< load */ | |
| 689 NULL, /**< unload */ | |
| 690 NULL, /**< destroy */ | |
| 691 | |
| 692 NULL, /**< ui_info */ | |
| 693 &prpl_info /**< extra_info */ | |
| 694 }; | |
| 695 | |
| 696 static void init_plugin(GaimPlugin *plugin) | |
| 697 { | |
| 698 GaimAccountUserSplit *split; | |
| 699 GaimAccountOption *option; | |
| 8631 | 700 char hostname[255]; |
| 701 | |
| 702 if (gethostname(hostname, 255) != 0) { | |
| 703 gaim_debug_warning("rendezvous", "Error %d when getting host name. Using \"localhost.\"\n", errno); | |
| 704 strcpy(hostname, "localhost"); | |
| 705 } | |
| 8487 | 706 |
| 707 /* Try to avoid making this configurable... */ | |
| 8631 | 708 split = gaim_account_user_split_new(_("Host Name"), hostname, '@'); |
| 8487 | 709 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
| 710 | |
| 711 option = gaim_account_option_string_new(_("First Name"), "first", "Gaim"); | |
| 712 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
| 713 option); | |
| 714 | |
| 715 option = gaim_account_option_string_new(_("Last Name"), "last", _("User")); | |
| 716 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
| 717 option); | |
| 718 | |
| 8631 | 719 option = gaim_account_option_bool_new(_("Share AIM screen name"), "shareaim", FALSE); |
| 8487 | 720 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
| 721 option); | |
| 722 | |
| 723 my_protocol = plugin; | |
| 724 } | |
| 725 | |
| 726 GAIM_INIT_PLUGIN(rendezvous, init_plugin, info); |
