Changes in protocols/purple/purple.c [9f03c47:a9e0de2]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/purple.c
r9f03c47 ra9e0de2 114 114 } 115 115 116 static gboolean purple_account_should_set_nick(account_t *acc) 117 { 118 /* whitelist of protocols that tend to have numeric or meaningless usernames, and should 119 * always offer the 'alias' as a nick. this is just so that users don't have to do 120 * 'account whatever set nick_format %full_name' 121 */ 122 char *whitelist[] = { 123 "prpl-hangouts", 124 "prpl-eionrobb-funyahoo-plusplus", 125 "prpl-icq", 126 "prpl-line", 127 NULL, 128 }; 129 char **p; 130 131 for (p = whitelist; *p; p++) { 132 if (g_strcmp0(acc->prpl->data, *p) == 0) { 133 return TRUE; 134 } 135 } 136 137 return FALSE; 138 } 139 116 140 static void purple_init(account_t *acc) 117 141 { … … 281 305 } 282 306 307 if (g_strcmp0(prpl->info->id, "prpl-line") == 0) { 308 s = set_add(&acc->set, "line-auth-token", NULL, NULL, acc); 309 s->flags |= SET_HIDDEN; 310 } 311 283 312 /* Go through all away states to figure out if away/status messages 284 313 are possible. */ … … 339 368 purple_account_set_check_mail(pa, set_getbool(&acc->set, "mail_notifications")); 340 369 } 370 371 if (g_strcmp0(prpl->info->id, "prpl-line") == 0) { 372 const char *name = "line-auth-token"; 373 purple_account_set_string(pa, name, set_getstr(&acc->set, name)); 374 } 341 375 } 342 376 … … 367 401 purple_account_set_password(pd->account, acc->pass); 368 402 purple_sync_settings(acc, pd->account); 403 404 if (purple_account_should_set_nick(acc)) { 405 pd->flags = PURPLE_OPT_SHOULD_SET_NICK; 406 } 369 407 370 408 purple_account_set_enabled(pd->account, "BitlBee", TRUE); … … 736 774 struct groupchat *gc; 737 775 GList *info, *l; 776 GString *missing_settings = NULL; 738 777 739 778 if (!pi->chat_info || !pi->chat_info_defaults || … … 761 800 } else if (strcmp(pce->identifier, "passwd") == 0) { 762 801 g_hash_table_replace(chat_hash, "passwd", g_strdup(password)); 802 } else { 803 char *key, *value; 804 805 key = g_strdup_printf("purple_%s", pce->identifier); 806 str_reject_chars(key, " -", '_'); 807 808 if ((value = set_getstr(sets, key))) { 809 /* sync from bitlbee to the prpl */ 810 g_hash_table_replace(chat_hash, (char *) pce->identifier, g_strdup(value)); 811 } else if ((value = g_hash_table_lookup(chat_hash, pce->identifier))) { 812 /* if the bitlbee one was empty, sync from prpl to bitlbee */ 813 set_setstr(sets, key, value); 814 } 815 816 g_free(key); 817 } 818 819 if (pce->required && !g_hash_table_lookup(chat_hash, pce->identifier)) { 820 if (!missing_settings) { 821 missing_settings = g_string_sized_new(32); 822 } 823 g_string_append_printf(missing_settings, "%s, ", pce->identifier); 763 824 } 764 825 … … 767 828 768 829 g_list_free(info); 830 831 if (missing_settings) { 832 /* remove the ", " from the end */ 833 g_string_truncate(missing_settings, missing_settings->len - 2); 834 835 imcb_error(ic, "Can't join %s. The following settings are required: %s", room, missing_settings->str); 836 837 g_string_free(missing_settings, TRUE); 838 g_hash_table_destroy(chat_hash); 839 return NULL; 840 } 769 841 770 842 /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */ … … 801 873 purple_roomlist_ref(list); 802 874 } 875 } 876 877 /* handles either prpl->chat_(add|free)_settings depending on the value of 'add' */ 878 static void purple_chat_update_settings(account_t *acc, set_t **head, gboolean add) 879 { 880 PurplePlugin *prpl = purple_plugins_find_with_id((char *) acc->prpl->data); 881 PurplePluginProtocolInfo *pi = prpl->info->extra_info; 882 GList *info, *l; 883 884 if (!pi->chat_info || !pi->chat_info_defaults) { 885 return; 886 } 887 888 /* hack / leap of faith: pass a NULL here because we don't have a connection yet. 889 * i reviewed all the built-in prpls and a bunch of third-party ones and none 890 * of them seem to need this parameter at all, so... i hope it never crashes */ 891 info = pi->chat_info(NULL); 892 893 for (l = info; l; l = l->next) { 894 struct proto_chat_entry *pce = l->data; 895 char *key; 896 897 if (strcmp(pce->identifier, "handle") == 0 || 898 strcmp(pce->identifier, "password") == 0 || 899 strcmp(pce->identifier, "passwd") == 0) { 900 /* skip these, they are handled above */ 901 g_free(pce); 902 continue; 903 } 904 905 key = g_strdup_printf("purple_%s", pce->identifier); 906 str_reject_chars(key, " -", '_'); 907 908 if (add) { 909 set_add(head, key, NULL, NULL, NULL); 910 } else { 911 set_del(head, key); 912 } 913 914 g_free(key); 915 g_free(pce); 916 } 917 918 g_list_free(NULL); 919 g_list_free(info); 920 } 921 922 static void purple_chat_add_settings(account_t *acc, set_t **head) 923 { 924 purple_chat_update_settings(acc, head, TRUE); 925 } 926 927 static void purple_chat_free_settings(account_t *acc, set_t **head) 928 { 929 purple_chat_update_settings(acc, head, FALSE); 803 930 } 804 931 … … 839 966 { 840 967 struct im_connection *ic = purple_ic_by_gc(gc); 841 const char *dn; 968 struct purple_data *pd = ic->proto_data; 969 const char *dn, *token; 842 970 set_t *s; 843 971 … … 852 980 // user list needs to be requested for Gadu-Gadu 853 981 purple_gg_buddylist_import(gc); 982 983 /* more awful hacks, because clearly we didn't have enough of those */ 984 if ((s = set_find(&ic->acc->set, "line-auth-token")) && 985 (token = purple_account_get_string(pd->account, "line-auth-token", NULL))) { 986 g_free(s->value); 987 s->value = g_strdup(token); 988 } 854 989 855 990 ic->flags |= OPT_DOES_HTML; … … 903 1038 PurpleGroup *group = purple_buddy_get_group(bud); 904 1039 struct im_connection *ic = purple_ic_by_pa(bud->account); 1040 struct purple_data *pd = ic->proto_data; 905 1041 PurpleStatus *as; 906 1042 int flags = 0; 1043 char *alias = NULL; 907 1044 908 1045 if (ic == NULL) { … … 910 1047 } 911 1048 912 if (bud->server_alias) { 913 imcb_rename_buddy(ic, bud->name, bud->server_alias); 914 } else if (bud->alias) { 915 imcb_rename_buddy(ic, bud->name, bud->alias); 1049 alias = bud->server_alias ? : bud->alias; 1050 1051 if (alias) { 1052 imcb_rename_buddy(ic, bud->name, alias); 1053 if (pd->flags & PURPLE_OPT_SHOULD_SET_NICK) { 1054 imcb_buddy_nick_change(ic, bud->name, alias); 1055 } 916 1056 } 917 1057 … … 1057 1197 } 1058 1198 1059 /* Handles write_im and write_chat. Removes echoes of locally sent messages */ 1199 /* Handles write_im and write_chat. Removes echoes of locally sent messages. 1200 * 1201 * PURPLE_MESSAGE_DELAYED is used for chat backlogs - if a message has both 1202 * that flag and _SEND, it's a self-message from before joining the channel. 1203 * Those are safe to display. The rest (with just _SEND) may be echoes. */ 1060 1204 static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) 1061 1205 { 1062 if ( !(flags & PURPLE_MESSAGE_SEND)) {1063 handle_conv_msg(conv, who, message, 0, mtime);1206 if ((!(flags & PURPLE_MESSAGE_SEND)) || (flags & PURPLE_MESSAGE_DELAYED)) { 1207 handle_conv_msg(conv, who, message, (flags & PURPLE_MESSAGE_SEND) ? OPT_SELFMESSAGE : 0, mtime); 1064 1208 } 1065 1209 } … … 1387 1531 } 1388 1532 1533 static char *prplcb_roomlist_get_room_name(PurpleRoomlist *list, PurpleRoomlistRoom *room) 1534 { 1535 struct im_connection *ic = purple_ic_by_pa(list->account); 1536 struct purple_data *pd = ic->proto_data; 1537 PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); 1538 PurplePluginProtocolInfo *pi = prpl->info->extra_info; 1539 1540 if (pi && pi->roomlist_room_serialize) { 1541 return pi->roomlist_room_serialize(room); 1542 } else { 1543 return g_strdup(purple_roomlist_room_get_name(room)); 1544 } 1545 } 1546 1389 1547 static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) 1390 1548 { 1391 1549 bee_chat_info_t *ci; 1392 c onst char *title;1550 char *title; 1393 1551 const char *topic; 1394 1552 GList *fields; … … 1396 1554 1397 1555 fields = purple_roomlist_room_get_fields(room); 1398 title = p urple_roomlist_room_get_name(room);1556 title = prplcb_roomlist_get_room_name(list, room); 1399 1557 1400 1558 if (rld->topic >= 0) { … … 1405 1563 1406 1564 ci = g_new(bee_chat_info_t, 1); 1407 ci->title = g_strdup(title);1565 ci->title = title; 1408 1566 ci->topic = g_strdup(topic); 1409 1567 rld->chats = g_slist_prepend(rld->chats, ci); … … 1627 1785 } 1628 1786 1787 /* borrowing this semi-private function 1788 * TODO: figure out a better interface later (famous last words) */ 1789 gboolean plugin_info_add(struct plugin_info *info); 1790 1629 1791 void purple_initmodule() 1630 1792 { … … 1633 1795 GString *help; 1634 1796 char *dir; 1797 gboolean debug_enabled = !!getenv("BITLBEE_DEBUG"); 1635 1798 1636 1799 if (purple_get_core() != NULL) { … … 1640 1803 } 1641 1804 1642 g_ assert((int) B_EV_IO_READ == (int) PURPLE_INPUT_READ);1643 g_ assert((int) B_EV_IO_WRITE == (int) PURPLE_INPUT_WRITE);1805 g_return_if_fail((int) B_EV_IO_READ == (int) PURPLE_INPUT_READ); 1806 g_return_if_fail((int) B_EV_IO_WRITE == (int) PURPLE_INPUT_WRITE); 1644 1807 1645 1808 dir = g_strdup_printf("%s/purple", global.conf->configdir); … … 1651 1814 g_free(dir); 1652 1815 1653 purple_debug_set_enabled( FALSE);1816 purple_debug_set_enabled(debug_enabled); 1654 1817 purple_core_set_ui_ops(&bee_core_uiops); 1655 1818 purple_eventloop_set_ui_ops(&glib_eventloops); … … 1659 1822 abort(); 1660 1823 } 1824 purple_debug_set_enabled(FALSE); 1661 1825 1662 1826 if (proxytype != PROXY_NONE) { … … 1717 1881 funcs.chat_join = purple_chat_join; 1718 1882 funcs.chat_list = purple_chat_list; 1883 funcs.chat_add_settings = purple_chat_add_settings; 1884 funcs.chat_free_settings = purple_chat_free_settings; 1719 1885 funcs.transfer_request = purple_transfer_request; 1720 1886 … … 1727 1893 PurplePluginProtocolInfo *pi = prot->info->extra_info; 1728 1894 struct prpl *ret; 1895 struct plugin_info *info; 1729 1896 1730 1897 /* If we already have this one (as a native module), don't … … 1761 1928 register_protocol(ret); 1762 1929 } 1930 1931 info = g_new0(struct plugin_info, 1); 1932 info->abiver = BITLBEE_ABI_VERSION_CODE; 1933 info->name = ret->name; 1934 info->version = prot->info->version; 1935 info->description = prot->info->description; 1936 info->author = prot->info->author; 1937 info->url = prot->info->homepage; 1938 1939 plugin_info_add(info); 1763 1940 } 1764 1941
Note: See TracChangeset
for help on using the changeset viewer.