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