Ignore:
Timestamp:
2018-03-10T11:30:39Z (6 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
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.
Message:

Merge branch 'master' into HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    r3f44e43 r7a9d968  
    114114}
    115115
     116static 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
    116140static void purple_init(account_t *acc)
    117141{
     
    281305        }
    282306
     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
    283312        /* Go through all away states to figure out if away/status messages
    284313           are possible. */
     
    344373                purple_account_set_check_mail(pa, set_getbool(&acc->set, "mail_notifications"));
    345374        }
     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        }
    346380}
    347381
     
    372406        purple_account_set_password(pd->account, acc->pass);
    373407        purple_sync_settings(acc, pd->account);
     408
     409        if (purple_account_should_set_nick(acc)) {
     410                pd->flags = PURPLE_OPT_SHOULD_SET_NICK;
     411        }
    374412
    375413        purple_account_set_enabled(pd->account, "BitlBee", TRUE);
     
    741779        struct groupchat *gc;
    742780        GList *info, *l;
     781        GString *missing_settings = NULL;
    743782
    744783        if (!pi->chat_info || !pi->chat_info_defaults ||
     
    766805                } else if (strcmp(pce->identifier, "passwd") == 0) {
    767806                        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);
    768829                }
    769830
     
    772833
    773834        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        }
    774846
    775847        /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */
     
    806878                purple_roomlist_ref(list);
    807879        }
     880}
     881
     882/* handles either prpl->chat_(add|free)_settings depending on the value of 'add' */
     883static 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
     927static void purple_chat_add_settings(account_t *acc, set_t **head)
     928{
     929        purple_chat_update_settings(acc, head, TRUE);
     930}
     931
     932static void purple_chat_free_settings(account_t *acc, set_t **head)
     933{
     934        purple_chat_update_settings(acc, head, FALSE);
    808935}
    809936
     
    844971{
    845972        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;
    847975        set_t *s;
    848976
     
    857985        // user list needs to be requested for Gadu-Gadu
    858986        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        }
    859994
    860995        ic->flags |= OPT_DOES_HTML;
     
    9081043                PurpleGroup *group = purple_buddy_get_group(bud);
    9091044                struct im_connection *ic = purple_ic_by_pa(bud->account);
     1045                struct purple_data *pd = ic->proto_data;
    9101046                PurpleStatus *as;
    9111047                int flags = 0;
     1048                char *alias = NULL;
    9121049
    9131050                if (ic == NULL) {
     
    9151052                }
    9161053
    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                        }
    9211061                }
    9221062
     
    10621202}
    10631203
    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. */
    10651209static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime)
    10661210{
    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);
    10691213        }
    10701214}
     
    13921536}
    13931537
     1538static 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
    13941552static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room)
    13951553{
    13961554        bee_chat_info_t *ci;
    1397         const char *title;
     1555        char *title;
    13981556        const char *topic;
    13991557        GList *fields;
     
    14011559
    14021560        fields = purple_roomlist_room_get_fields(room);
    1403         title = purple_roomlist_room_get_name(room);
     1561        title = prplcb_roomlist_get_room_name(list, room);
    14041562
    14051563        if (rld->topic >= 0) {
     
    14101568
    14111569        ci = g_new(bee_chat_info_t, 1);
    1412         ci->title = g_strdup(title);
     1570        ci->title = title;
    14131571        ci->topic = g_strdup(topic);
    14141572        rld->chats = g_slist_prepend(rld->chats, ci);
     
    16321790}
    16331791
     1792/* borrowing this semi-private function
     1793 * TODO: figure out a better interface later (famous last words) */
     1794gboolean plugin_info_add(struct plugin_info *info);
     1795
    16341796void purple_initmodule()
    16351797{
     
    16381800        GString *help;
    16391801        char *dir;
     1802        gboolean debug_enabled = !!getenv("BITLBEE_DEBUG");
    16401803
    16411804        if (purple_get_core() != NULL) {
     
    16451808        }
    16461809
    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);
    16491812
    16501813        dir = g_strdup_printf("%s/purple", global.conf->configdir);
     
    16561819        g_free(dir);
    16571820
    1658         purple_debug_set_enabled(FALSE);
     1821        purple_debug_set_enabled(debug_enabled);
    16591822        purple_core_set_ui_ops(&bee_core_uiops);
    16601823        purple_eventloop_set_ui_ops(&glib_eventloops);
     
    16641827                abort();
    16651828        }
     1829        purple_debug_set_enabled(FALSE);
    16661830
    16671831        if (proxytype != PROXY_NONE) {
     
    17221886        funcs.chat_join = purple_chat_join;
    17231887        funcs.chat_list = purple_chat_list;
     1888        funcs.chat_add_settings = purple_chat_add_settings;
     1889        funcs.chat_free_settings = purple_chat_free_settings;
    17241890        funcs.transfer_request = purple_transfer_request;
    17251891
     
    17321898                PurplePluginProtocolInfo *pi = prot->info->extra_info;
    17331899                struct prpl *ret;
     1900                struct plugin_info *info;
    17341901
    17351902                /* If we already have this one (as a native module), don't
     
    17661933                        register_protocol(ret);
    17671934                }
     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);
    17681945        }
    17691946
Note: See TracChangeset for help on using the changeset viewer.