Mercurial > pidgin
comparison src/protocols/silc/buddy.c @ 9030:7ab20f829190
[gaim-migrate @ 9806]
Siege updated the code for creating right-click menu's for
buddies, chats, groups, etc. It uses more stuff from the blist
API and less stuff from multi.h. It also combines the code
for right-click menus for chats, buddies, etc. (all types of
blist nodes). So PRPLs and plugins can easily add right-click
menu options to anything in the buddy list in a clean way.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 23 May 2004 17:27:45 +0000 |
parents | 26c9b8761707 |
children | 095731b5e4f6 |
comparison
equal
deleted
inserted
replaced
9029:697e169dac12 | 9030:7ab20f829190 |
---|---|
312 | 312 |
313 | 313 |
314 /**************************** Static IM Key **********************************/ | 314 /**************************** Static IM Key **********************************/ |
315 | 315 |
316 static void | 316 static void |
317 silcgaim_buddy_resetkey(GaimConnection *gc, const char *name) | 317 silcgaim_buddy_resetkey(GaimBlistNode *node, gpointer data) |
318 { | 318 { |
319 SilcGaim sg = gc->proto_data; | 319 GaimBuddy *b; |
320 GaimConnection *gc; | |
321 SilcGaim sg; | |
320 char *nickname; | 322 char *nickname; |
321 SilcClientEntry *clients; | 323 SilcClientEntry *clients; |
322 SilcUInt32 clients_count; | 324 SilcUInt32 clients_count; |
323 | 325 |
324 if (!name) | 326 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
325 return; | 327 |
326 if (!silc_parse_userfqdn(name, &nickname, NULL)) | 328 b = (GaimBuddy *) node; |
329 gc = gaim_account_get_connection(b->account); | |
330 sg = gc->proto_data; | |
331 | |
332 if (!silc_parse_userfqdn(b->name, &nickname, NULL)) | |
327 return; | 333 return; |
328 | 334 |
329 /* Find client entry */ | 335 /* Find client entry */ |
330 clients = silc_client_get_clients_local(sg->client, sg->conn, | 336 clients = silc_client_get_clients_local(sg->client, sg->conn, |
331 nickname, name, | 337 nickname, b->name, |
332 &clients_count); | 338 &clients_count); |
333 if (!clients) { | 339 if (!clients) { |
334 silc_free(nickname); | 340 silc_free(nickname); |
335 return; | 341 return; |
336 } | 342 } |
409 silcgaim_buddy_privkey(client->application, context); | 415 silcgaim_buddy_privkey(client->application, context); |
410 silc_free(context); | 416 silc_free(context); |
411 } | 417 } |
412 | 418 |
413 static void | 419 static void |
414 silcgaim_buddy_privkey(GaimConnection *gc, const char *name) | 420 silcgaim_buddy_privkey(GaimBlistNode *node, gpointer data) |
415 { | 421 { |
416 SilcGaim sg = gc->proto_data; | 422 GaimBuddy *b; |
423 GaimConnection *gc; | |
424 SilcGaim sg; | |
417 char *nickname; | 425 char *nickname; |
418 SilcGaimPrivkey p; | 426 SilcGaimPrivkey p; |
419 SilcClientEntry *clients; | 427 SilcClientEntry *clients; |
420 SilcUInt32 clients_count; | 428 SilcUInt32 clients_count; |
421 | 429 |
422 if (!name) | 430 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
423 return; | 431 |
424 if (!silc_parse_userfqdn(name, &nickname, NULL)) | 432 b = (GaimBuddy *) node; |
433 gc = gaim_account_get_connection(b->account); | |
434 sg = gc->proto_data; | |
435 | |
436 if (!silc_parse_userfqdn(b->name, &nickname, NULL)) | |
425 return; | 437 return; |
426 | 438 |
427 /* Find client entry */ | 439 /* Find client entry */ |
428 clients = silc_client_get_clients_local(sg->client, sg->conn, | 440 clients = silc_client_get_clients_local(sg->client, sg->conn, |
429 nickname, name, | 441 nickname, b->name, |
430 &clients_count); | 442 &clients_count); |
431 if (!clients) { | 443 if (!clients) { |
432 silc_client_get_clients(sg->client, sg->conn, nickname, NULL, | 444 silc_client_get_clients(sg->client, sg->conn, nickname, NULL, |
433 silcgaim_buddy_privkey_resolved, | 445 silcgaim_buddy_privkey_resolved, |
434 g_strdup(name)); | 446 g_strdup(b->name)); |
435 silc_free(nickname); | 447 silc_free(nickname); |
436 return; | 448 return; |
437 } | 449 } |
438 | 450 |
439 p = silc_calloc(1, sizeof(*p)); | 451 p = silc_calloc(1, sizeof(*p)); |
520 silcgaim_buddy_getkey(client->application, context); | 532 silcgaim_buddy_getkey(client->application, context); |
521 silc_free(context); | 533 silc_free(context); |
522 } | 534 } |
523 | 535 |
524 static void | 536 static void |
525 silcgaim_buddy_getkey(GaimConnection *gc, const char *name) | 537 silcgaim_buddy_getkey(GaimBlistNode *node, gpointer data) |
526 { | 538 { |
527 SilcGaim sg = gc->proto_data; | 539 GaimBuddy *b; |
528 SilcClient client = sg->client; | 540 GaimConnection *gc; |
529 SilcClientConnection conn = sg->conn; | 541 SilcGaim sg; |
542 SilcClient client; | |
543 SilcClientConnection; | |
530 SilcClientEntry *clients; | 544 SilcClientEntry *clients; |
531 SilcUInt32 clients_count; | 545 SilcUInt32 clients_count; |
532 SilcGaimBuddyGetkey g; | 546 SilcGaimBuddyGetkey g; |
533 char *nickname; | 547 char *nickname; |
534 | 548 |
535 if (!name) | 549 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
536 return; | 550 |
537 | 551 b = (GaimBuddy *) node; |
538 if (!silc_parse_userfqdn(name, &nickname, NULL)) | 552 gc = gaim_account_get_connection(b->account); |
553 sg = gc->proto_data; | |
554 client = sg->client; | |
555 conn = sg->conn; | |
556 | |
557 if (!silc_parse_userfqdn(b->name, &nickname, NULL)) | |
539 return; | 558 return; |
540 | 559 |
541 /* Find client entry */ | 560 /* Find client entry */ |
542 clients = silc_client_get_clients_local(client, conn, nickname, name, | 561 clients = silc_client_get_clients_local(client, conn, nickname, |
543 &clients_count); | 562 b->name, &clients_count); |
544 if (!clients) { | 563 if (!clients) { |
545 silc_client_get_clients(client, conn, nickname, NULL, | 564 silc_client_get_clients(client, conn, nickname, NULL, |
546 silcgaim_buddy_getkey_resolved, | 565 silcgaim_buddy_getkey_resolved, |
547 g_strdup(name)); | 566 g_strdup(b->name)); |
548 silc_free(nickname); | 567 silc_free(nickname); |
549 return; | 568 return; |
550 } | 569 } |
551 | 570 |
552 /* Call GETKEY */ | 571 /* Call GETKEY */ |
564 silc_free(clients); | 583 silc_free(clients); |
565 silc_free(nickname); | 584 silc_free(nickname); |
566 } | 585 } |
567 | 586 |
568 static void | 587 static void |
569 silcgaim_buddy_showkey(GaimConnection *gc, const char *name) | 588 silcgaim_buddy_showkey(GaimBlistNode *node, gpointer data) |
570 { | 589 { |
571 SilcGaim sg = gc->proto_data; | 590 GaimBuddy *b; |
591 GaimConnection *gc; | |
592 SilcGaim sg; | |
572 SilcPublicKey public_key; | 593 SilcPublicKey public_key; |
573 const char *pkfile; | 594 const char *pkfile; |
574 GaimBuddy *b; | 595 |
575 | 596 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
576 b = gaim_find_buddy(gc->account, name); | 597 |
577 if (!b) | 598 b = (GaimBuddy *) node; |
578 return; | 599 gc = gaim_account_get_connection(b->account); |
579 | 600 sg = gc->proto_data; |
580 pkfile = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); | 601 |
602 pkfile = gaim_blist_node_get_string(buddy, "public-key"); | |
581 if (!silc_pkcs_load_public_key(pkfile, &public_key, SILC_PKCS_FILE_PEM) && | 603 if (!silc_pkcs_load_public_key(pkfile, &public_key, SILC_PKCS_FILE_PEM) && |
582 !silc_pkcs_load_public_key(pkfile, &public_key, SILC_PKCS_FILE_BIN)) { | 604 !silc_pkcs_load_public_key(pkfile, &public_key, SILC_PKCS_FILE_BIN)) { |
583 gaim_notify_error(gc, | 605 gaim_notify_error(gc, |
584 _("Show Public Key"), | 606 _("Show Public Key"), |
585 _("Could not load public key"), NULL); | 607 _("Could not load public key"), NULL); |
586 return; | 608 return; |
587 } | 609 } |
588 | 610 |
589 silcgaim_show_public_key(sg, name, public_key, NULL, NULL); | 611 silcgaim_show_public_key(sg, b->name, public_key, NULL, NULL); |
590 silc_pkcs_public_key_free(public_key); | 612 silc_pkcs_public_key_free(public_key); |
591 } | 613 } |
592 | 614 |
593 | 615 |
594 /**************************** Buddy routines *********************************/ | 616 /**************************** Buddy routines *********************************/ |
1534 buf = g_string_free(s, FALSE); | 1556 buf = g_string_free(s, FALSE); |
1535 return buf; | 1557 return buf; |
1536 } | 1558 } |
1537 | 1559 |
1538 static void | 1560 static void |
1539 silcgaim_buddy_kill(GaimConnection *gc, const char *name) | 1561 silcgaim_buddy_kill(GaimBlistNode *buddy, gpointer data) |
1540 { | 1562 { |
1541 SilcGaim sg = gc->proto_data; | 1563 GaimBuddy *b; |
1542 SilcClient client = sg->client; | 1564 GaimConnection *gc; |
1543 SilcClientConnection conn = sg->conn; | 1565 SilcGaim sg; |
1566 | |
1567 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
1568 | |
1569 b = (GaimBuddy *) node; | |
1570 gc = gaim_account_get_connection(b->account); | |
1571 sg = gc->proto_data; | |
1544 | 1572 |
1545 /* Call KILL */ | 1573 /* Call KILL */ |
1546 silc_client_command_call(client, conn, NULL, "KILL", | 1574 silc_client_command_call(sg->client, sg->conn, NULL, "KILL", |
1547 name, "Killed by operator", NULL); | 1575 b->name, "Killed by operator", NULL); |
1548 } | 1576 } |
1549 | 1577 |
1550 static void | 1578 static void |
1551 silcgaim_buddy_send_file(GaimConnection *gc, const char *name) | 1579 silcgaim_buddy_send_file(GaimBlistNode *buddy, gpointer data) |
1552 { | 1580 { |
1553 silcgaim_ftp_send_file(gc, name); | 1581 GaimBuddy *b; |
1554 } | 1582 GaimConnection *gc; |
1555 | 1583 |
1556 GList *silcgaim_buddy_menu(GaimConnection *gc, const char *name) | 1584 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
1557 { | 1585 |
1586 b = (GaimBuddy *) node; | |
1587 gc = gaim_account_get_connection(b->account); | |
1588 | |
1589 silcgaim_ftp_send_file(gc, b->name); | |
1590 } | |
1591 | |
1592 GList *silcgaim_buddy_menu(GaimBuddy *buddy) | |
1593 { | |
1594 | |
1595 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
1558 SilcGaim sg = gc->proto_data; | 1596 SilcGaim sg = gc->proto_data; |
1559 SilcClientConnection conn = sg->conn; | 1597 SilcClientConnection conn = sg->conn; |
1560 GList *m = NULL; | |
1561 struct proto_buddy_menu *pbm; | |
1562 GaimBuddy *b; | |
1563 const char *pkfile = NULL; | 1598 const char *pkfile = NULL; |
1564 SilcClientEntry client_entry = NULL; | 1599 SilcClientEntry client_entry = NULL; |
1565 | 1600 GaimBlistNodeAction *act; |
1566 b = gaim_find_buddy(gc->account, name); | 1601 GList *m = NULL; |
1567 if (b) { | 1602 |
1568 pkfile = gaim_blist_node_get_string((GaimBlistNode *)b, "public-key"); | 1603 pkfile = gaim_blist_node_get_string(node, "public-key"); |
1569 client_entry = silc_client_get_client_by_id(sg->client, | 1604 client_entry = silc_client_get_client_by_id(sg->client, |
1570 sg->conn, | 1605 sg->conn, |
1571 b->proto_data); | 1606 b->proto_data); |
1572 } | |
1573 | 1607 |
1574 if (client_entry && client_entry->send_key) { | 1608 if (client_entry && client_entry->send_key) { |
1575 pbm = g_new0(struct proto_buddy_menu, 1); | 1609 act = gaim_blist_node_action_new(_("Reset IM Key"), |
1576 pbm->label = _("Reset IM Key"); | 1610 silcgaim_buddy_resetkey); |
1577 pbm->callback = silcgaim_buddy_resetkey; | 1611 m = g_list_append(m, act); |
1578 pbm->gc = gc; | 1612 |
1579 m = g_list_append(m, pbm); | |
1580 } else { | 1613 } else { |
1581 pbm = g_new0(struct proto_buddy_menu, 1); | 1614 act = gaim_blist_node_action_new(_("IM with Key Exchange"), |
1582 pbm->label = _("IM with Key Exchange"); | 1615 silcgaim_buddy_keyagr); |
1583 pbm->callback = silcgaim_buddy_keyagr; | 1616 m = g_list_append(m, act); |
1584 pbm->gc = gc; | 1617 |
1585 m = g_list_append(m, pbm); | 1618 act = gaim_blist_node_action_new(_("IM with Password"), |
1586 | 1619 silcgaim_buddy_privkey); |
1587 pbm = g_new0(struct proto_buddy_menu, 1); | 1620 m = g_list_append(m, act); |
1588 pbm->label = _("IM with Password"); | |
1589 pbm->callback = silcgaim_buddy_privkey; | |
1590 pbm->gc = gc; | |
1591 m = g_list_append(m, pbm); | |
1592 } | 1621 } |
1593 | 1622 |
1594 if (pkfile) { | 1623 if (pkfile) { |
1595 pbm = g_new0(struct proto_buddy_menu, 1); | 1624 act = gaim_blist_node_action_new(_("Show Public Key"), |
1596 pbm->label = _("Show Public Key"); | 1625 silcgaim_buddy_showkey); |
1597 pbm->callback = silcgaim_buddy_showkey; | 1626 m = g_list_append(m, act); |
1598 pbm->gc = gc; | 1627 |
1599 m = g_list_append(m, pbm); | |
1600 } else { | 1628 } else { |
1601 pbm = g_new0(struct proto_buddy_menu, 1); | 1629 act = gaim_blist_node_action_new(_("Get Public Key..."), |
1602 pbm->label = _("Get Public Key..."); | 1630 silcgaim_buddy_getkey); |
1603 pbm->callback = silcgaim_buddy_getkey; | 1631 m = g_list_append(m, act); |
1604 pbm->gc = gc; | 1632 } |
1605 m = g_list_append(m, pbm); | 1633 |
1606 } | 1634 act = gaim_blist_node_action_new(_("Send File..."), |
1607 | 1635 silcgaim_buddy_send_file); |
1608 pbm = g_new0(struct proto_buddy_menu, 1); | 1636 m = g_list_append(m, act); |
1609 pbm->label = _("Send File..."); | |
1610 pbm->callback = silcgaim_buddy_send_file; | |
1611 pbm->gc = gc; | |
1612 m = g_list_append(m, pbm); | |
1613 | 1637 |
1614 if (conn && conn->local_entry->mode & SILC_UMODE_ROUTER_OPERATOR) { | 1638 if (conn && conn->local_entry->mode & SILC_UMODE_ROUTER_OPERATOR) { |
1615 pbm = g_new0(struct proto_buddy_menu, 1); | 1639 act = gaim_blist_node_action_new(_("Kill User"), |
1616 pbm->label = _("Kill User"); | 1640 silcgaim_buddy_kill); |
1617 pbm->callback = silcgaim_buddy_kill; | 1641 m = g_list_append(m, act); |
1618 pbm->gc = gc; | |
1619 m = g_list_append(m, pbm); | |
1620 } | 1642 } |
1621 | 1643 |
1622 return m; | 1644 return m; |
1623 } | 1645 } |