Changes in protocols/purple/purple.c [a9e0de2:9f03c47]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/purple.c
ra9e0de2 r9f03c47 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 should119 * always offer the 'alias' as a nick. this is just so that users don't have to do120 * '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 140 116 static void purple_init(account_t *acc) 141 117 { … … 305 281 } 306 282 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 312 283 /* Go through all away states to figure out if away/status messages 313 284 are possible. */ … … 368 339 purple_account_set_check_mail(pa, set_getbool(&acc->set, "mail_notifications")); 369 340 } 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 }375 341 } 376 342 … … 401 367 purple_account_set_password(pd->account, acc->pass); 402 368 purple_sync_settings(acc, pd->account); 403 404 if (purple_account_should_set_nick(acc)) {405 pd->flags = PURPLE_OPT_SHOULD_SET_NICK;406 }407 369 408 370 purple_account_set_enabled(pd->account, "BitlBee", TRUE); … … 774 736 struct groupchat *gc; 775 737 GList *info, *l; 776 GString *missing_settings = NULL;777 738 778 739 if (!pi->chat_info || !pi->chat_info_defaults || … … 800 761 } else if (strcmp(pce->identifier, "passwd") == 0) { 801 762 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);824 763 } 825 764 … … 828 767 829 768 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 }841 769 842 770 /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */ … … 873 801 purple_roomlist_ref(list); 874 802 } 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 none890 * 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);930 803 } 931 804 … … 966 839 { 967 840 struct im_connection *ic = purple_ic_by_gc(gc); 968 struct purple_data *pd = ic->proto_data; 969 const char *dn, *token; 841 const char *dn; 970 842 set_t *s; 971 843 … … 980 852 // user list needs to be requested for Gadu-Gadu 981 853 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 }989 854 990 855 ic->flags |= OPT_DOES_HTML; … … 1038 903 PurpleGroup *group = purple_buddy_get_group(bud); 1039 904 struct im_connection *ic = purple_ic_by_pa(bud->account); 1040 struct purple_data *pd = ic->proto_data;1041 905 PurpleStatus *as; 1042 906 int flags = 0; 1043 char *alias = NULL;1044 907 1045 908 if (ic == NULL) { … … 1047 910 } 1048 911 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 } 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); 1056 916 } 1057 917 … … 1197 1057 } 1198 1058 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. */ 1059 /* Handles write_im and write_chat. Removes echoes of locally sent messages */ 1204 1060 static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) 1205 1061 { 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);1062 if (!(flags & PURPLE_MESSAGE_SEND)) { 1063 handle_conv_msg(conv, who, message, 0, mtime); 1208 1064 } 1209 1065 } … … 1531 1387 } 1532 1388 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 1547 1389 static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) 1548 1390 { 1549 1391 bee_chat_info_t *ci; 1550 c har *title;1392 const char *title; 1551 1393 const char *topic; 1552 1394 GList *fields; … … 1554 1396 1555 1397 fields = purple_roomlist_room_get_fields(room); 1556 title = p rplcb_roomlist_get_room_name(list,room);1398 title = purple_roomlist_room_get_name(room); 1557 1399 1558 1400 if (rld->topic >= 0) { … … 1563 1405 1564 1406 ci = g_new(bee_chat_info_t, 1); 1565 ci->title = title;1407 ci->title = g_strdup(title); 1566 1408 ci->topic = g_strdup(topic); 1567 1409 rld->chats = g_slist_prepend(rld->chats, ci); … … 1785 1627 } 1786 1628 1787 /* borrowing this semi-private function1788 * TODO: figure out a better interface later (famous last words) */1789 gboolean plugin_info_add(struct plugin_info *info);1790 1791 1629 void purple_initmodule() 1792 1630 { … … 1795 1633 GString *help; 1796 1634 char *dir; 1797 gboolean debug_enabled = !!getenv("BITLBEE_DEBUG");1798 1635 1799 1636 if (purple_get_core() != NULL) { … … 1803 1640 } 1804 1641 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);1642 g_assert((int) B_EV_IO_READ == (int) PURPLE_INPUT_READ); 1643 g_assert((int) B_EV_IO_WRITE == (int) PURPLE_INPUT_WRITE); 1807 1644 1808 1645 dir = g_strdup_printf("%s/purple", global.conf->configdir); … … 1814 1651 g_free(dir); 1815 1652 1816 purple_debug_set_enabled( debug_enabled);1653 purple_debug_set_enabled(FALSE); 1817 1654 purple_core_set_ui_ops(&bee_core_uiops); 1818 1655 purple_eventloop_set_ui_ops(&glib_eventloops); … … 1822 1659 abort(); 1823 1660 } 1824 purple_debug_set_enabled(FALSE);1825 1661 1826 1662 if (proxytype != PROXY_NONE) { … … 1881 1717 funcs.chat_join = purple_chat_join; 1882 1718 funcs.chat_list = purple_chat_list; 1883 funcs.chat_add_settings = purple_chat_add_settings;1884 funcs.chat_free_settings = purple_chat_free_settings;1885 1719 funcs.transfer_request = purple_transfer_request; 1886 1720 … … 1893 1727 PurplePluginProtocolInfo *pi = prot->info->extra_info; 1894 1728 struct prpl *ret; 1895 struct plugin_info *info;1896 1729 1897 1730 /* If we already have this one (as a native module), don't … … 1928 1761 register_protocol(ret); 1929 1762 } 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);1940 1763 } 1941 1764
Note: See TracChangeset
for help on using the changeset viewer.