Changeset 7a9d968 for protocols/purple/purple.c
- Timestamp:
- 2018-03-10T11:30:39Z (7 years ago)
- Children:
- 5447c59
- Parents:
- 3f44e43 (diff), 4a9c6b0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/purple.c
r3f44e43 r7a9d968 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. */ … … 344 373 purple_account_set_check_mail(pa, set_getbool(&acc->set, "mail_notifications")); 345 374 } 375 376 if (g_strcmp0(prpl->info->id, "prpl-line") == 0) { 377 const char *name = "line-auth-token"; 378 purple_account_set_string(pa, name, set_getstr(&acc->set, name)); 379 } 346 380 } 347 381 … … 372 406 purple_account_set_password(pd->account, acc->pass); 373 407 purple_sync_settings(acc, pd->account); 408 409 if (purple_account_should_set_nick(acc)) { 410 pd->flags = PURPLE_OPT_SHOULD_SET_NICK; 411 } 374 412 375 413 purple_account_set_enabled(pd->account, "BitlBee", TRUE); … … 741 779 struct groupchat *gc; 742 780 GList *info, *l; 781 GString *missing_settings = NULL; 743 782 744 783 if (!pi->chat_info || !pi->chat_info_defaults || … … 766 805 } else if (strcmp(pce->identifier, "passwd") == 0) { 767 806 g_hash_table_replace(chat_hash, "passwd", g_strdup(password)); 807 } else { 808 char *key, *value; 809 810 key = g_strdup_printf("purple_%s", pce->identifier); 811 str_reject_chars(key, " -", '_'); 812 813 if ((value = set_getstr(sets, key))) { 814 /* sync from bitlbee to the prpl */ 815 g_hash_table_replace(chat_hash, (char *) pce->identifier, g_strdup(value)); 816 } else if ((value = g_hash_table_lookup(chat_hash, pce->identifier))) { 817 /* if the bitlbee one was empty, sync from prpl to bitlbee */ 818 set_setstr(sets, key, value); 819 } 820 821 g_free(key); 822 } 823 824 if (pce->required && !g_hash_table_lookup(chat_hash, pce->identifier)) { 825 if (!missing_settings) { 826 missing_settings = g_string_sized_new(32); 827 } 828 g_string_append_printf(missing_settings, "%s, ", pce->identifier); 768 829 } 769 830 … … 772 833 773 834 g_list_free(info); 835 836 if (missing_settings) { 837 /* remove the ", " from the end */ 838 g_string_truncate(missing_settings, missing_settings->len - 2); 839 840 imcb_error(ic, "Can't join %s. The following settings are required: %s", room, missing_settings->str); 841 842 g_string_free(missing_settings, TRUE); 843 g_hash_table_destroy(chat_hash); 844 return NULL; 845 } 774 846 775 847 /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */ … … 806 878 purple_roomlist_ref(list); 807 879 } 880 } 881 882 /* handles either prpl->chat_(add|free)_settings depending on the value of 'add' */ 883 static void purple_chat_update_settings(account_t *acc, set_t **head, gboolean add) 884 { 885 PurplePlugin *prpl = purple_plugins_find_with_id((char *) acc->prpl->data); 886 PurplePluginProtocolInfo *pi = prpl->info->extra_info; 887 GList *info, *l; 888 889 if (!pi->chat_info || !pi->chat_info_defaults) { 890 return; 891 } 892 893 /* hack / leap of faith: pass a NULL here because we don't have a connection yet. 894 * i reviewed all the built-in prpls and a bunch of third-party ones and none 895 * of them seem to need this parameter at all, so... i hope it never crashes */ 896 info = pi->chat_info(NULL); 897 898 for (l = info; l; l = l->next) { 899 struct proto_chat_entry *pce = l->data; 900 char *key; 901 902 if (strcmp(pce->identifier, "handle") == 0 || 903 strcmp(pce->identifier, "password") == 0 || 904 strcmp(pce->identifier, "passwd") == 0) { 905 /* skip these, they are handled above */ 906 g_free(pce); 907 continue; 908 } 909 910 key = g_strdup_printf("purple_%s", pce->identifier); 911 str_reject_chars(key, " -", '_'); 912 913 if (add) { 914 set_add(head, key, NULL, NULL, NULL); 915 } else { 916 set_del(head, key); 917 } 918 919 g_free(key); 920 g_free(pce); 921 } 922 923 g_list_free(NULL); 924 g_list_free(info); 925 } 926 927 static void purple_chat_add_settings(account_t *acc, set_t **head) 928 { 929 purple_chat_update_settings(acc, head, TRUE); 930 } 931 932 static void purple_chat_free_settings(account_t *acc, set_t **head) 933 { 934 purple_chat_update_settings(acc, head, FALSE); 808 935 } 809 936 … … 844 971 { 845 972 struct im_connection *ic = purple_ic_by_gc(gc); 846 const char *dn; 973 struct purple_data *pd = ic->proto_data; 974 const char *dn, *token; 847 975 set_t *s; 848 976 … … 857 985 // user list needs to be requested for Gadu-Gadu 858 986 purple_gg_buddylist_import(gc); 987 988 /* more awful hacks, because clearly we didn't have enough of those */ 989 if ((s = set_find(&ic->acc->set, "line-auth-token")) && 990 (token = purple_account_get_string(pd->account, "line-auth-token", NULL))) { 991 g_free(s->value); 992 s->value = g_strdup(token); 993 } 859 994 860 995 ic->flags |= OPT_DOES_HTML; … … 908 1043 PurpleGroup *group = purple_buddy_get_group(bud); 909 1044 struct im_connection *ic = purple_ic_by_pa(bud->account); 1045 struct purple_data *pd = ic->proto_data; 910 1046 PurpleStatus *as; 911 1047 int flags = 0; 1048 char *alias = NULL; 912 1049 913 1050 if (ic == NULL) { … … 915 1052 } 916 1053 917 if (bud->server_alias) { 918 imcb_rename_buddy(ic, bud->name, bud->server_alias); 919 } else if (bud->alias) { 920 imcb_rename_buddy(ic, bud->name, bud->alias); 1054 alias = bud->server_alias ? : bud->alias; 1055 1056 if (alias) { 1057 imcb_rename_buddy(ic, bud->name, alias); 1058 if (pd->flags & PURPLE_OPT_SHOULD_SET_NICK) { 1059 imcb_buddy_nick_change(ic, bud->name, alias); 1060 } 921 1061 } 922 1062 … … 1062 1202 } 1063 1203 1064 /* Handles write_im and write_chat. Removes echoes of locally sent messages */ 1204 /* Handles write_im and write_chat. Removes echoes of locally sent messages. 1205 * 1206 * PURPLE_MESSAGE_DELAYED is used for chat backlogs - if a message has both 1207 * that flag and _SEND, it's a self-message from before joining the channel. 1208 * Those are safe to display. The rest (with just _SEND) may be echoes. */ 1065 1209 static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) 1066 1210 { 1067 if ( !(flags & PURPLE_MESSAGE_SEND)) {1068 handle_conv_msg(conv, who, message, 0, mtime);1211 if ((!(flags & PURPLE_MESSAGE_SEND)) || (flags & PURPLE_MESSAGE_DELAYED)) { 1212 handle_conv_msg(conv, who, message, (flags & PURPLE_MESSAGE_SEND) ? OPT_SELFMESSAGE : 0, mtime); 1069 1213 } 1070 1214 } … … 1392 1536 } 1393 1537 1538 static char *prplcb_roomlist_get_room_name(PurpleRoomlist *list, PurpleRoomlistRoom *room) 1539 { 1540 struct im_connection *ic = purple_ic_by_pa(list->account); 1541 struct purple_data *pd = ic->proto_data; 1542 PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); 1543 PurplePluginProtocolInfo *pi = prpl->info->extra_info; 1544 1545 if (pi && pi->roomlist_room_serialize) { 1546 return pi->roomlist_room_serialize(room); 1547 } else { 1548 return g_strdup(purple_roomlist_room_get_name(room)); 1549 } 1550 } 1551 1394 1552 static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) 1395 1553 { 1396 1554 bee_chat_info_t *ci; 1397 c onst char *title;1555 char *title; 1398 1556 const char *topic; 1399 1557 GList *fields; … … 1401 1559 1402 1560 fields = purple_roomlist_room_get_fields(room); 1403 title = p urple_roomlist_room_get_name(room);1561 title = prplcb_roomlist_get_room_name(list, room); 1404 1562 1405 1563 if (rld->topic >= 0) { … … 1410 1568 1411 1569 ci = g_new(bee_chat_info_t, 1); 1412 ci->title = g_strdup(title);1570 ci->title = title; 1413 1571 ci->topic = g_strdup(topic); 1414 1572 rld->chats = g_slist_prepend(rld->chats, ci); … … 1632 1790 } 1633 1791 1792 /* borrowing this semi-private function 1793 * TODO: figure out a better interface later (famous last words) */ 1794 gboolean plugin_info_add(struct plugin_info *info); 1795 1634 1796 void purple_initmodule() 1635 1797 { … … 1638 1800 GString *help; 1639 1801 char *dir; 1802 gboolean debug_enabled = !!getenv("BITLBEE_DEBUG"); 1640 1803 1641 1804 if (purple_get_core() != NULL) { … … 1645 1808 } 1646 1809 1647 g_ assert((int) B_EV_IO_READ == (int) PURPLE_INPUT_READ);1648 g_ assert((int) B_EV_IO_WRITE == (int) PURPLE_INPUT_WRITE);1810 g_return_if_fail((int) B_EV_IO_READ == (int) PURPLE_INPUT_READ); 1811 g_return_if_fail((int) B_EV_IO_WRITE == (int) PURPLE_INPUT_WRITE); 1649 1812 1650 1813 dir = g_strdup_printf("%s/purple", global.conf->configdir); … … 1656 1819 g_free(dir); 1657 1820 1658 purple_debug_set_enabled( FALSE);1821 purple_debug_set_enabled(debug_enabled); 1659 1822 purple_core_set_ui_ops(&bee_core_uiops); 1660 1823 purple_eventloop_set_ui_ops(&glib_eventloops); … … 1664 1827 abort(); 1665 1828 } 1829 purple_debug_set_enabled(FALSE); 1666 1830 1667 1831 if (proxytype != PROXY_NONE) { … … 1722 1886 funcs.chat_join = purple_chat_join; 1723 1887 funcs.chat_list = purple_chat_list; 1888 funcs.chat_add_settings = purple_chat_add_settings; 1889 funcs.chat_free_settings = purple_chat_free_settings; 1724 1890 funcs.transfer_request = purple_transfer_request; 1725 1891 … … 1732 1898 PurplePluginProtocolInfo *pi = prot->info->extra_info; 1733 1899 struct prpl *ret; 1900 struct plugin_info *info; 1734 1901 1735 1902 /* If we already have this one (as a native module), don't … … 1766 1933 register_protocol(ret); 1767 1934 } 1935 1936 info = g_new0(struct plugin_info, 1); 1937 info->abiver = BITLBEE_ABI_VERSION_CODE; 1938 info->name = ret->name; 1939 info->version = prot->info->version; 1940 info->description = prot->info->description; 1941 info->author = prot->info->author; 1942 info->url = prot->info->homepage; 1943 1944 plugin_info_add(info); 1768 1945 } 1769 1946
Note: See TracChangeset
for help on using the changeset viewer.