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