Changeset 1882b70 for protocols/purple


Ignore:
Timestamp:
2016-12-26T23:52:24Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
faa7abb6
Parents:
a04705b
Message:

purple: add support for extra groupchat settings (helps with SIPE)

This adds channel settings prefixed by purple_. For example jabber now
has purple_room and purple_server which are decomposed variants of our
own 'room' setting. Okay, that doesn't sound very useful.

It also adds some sync from the values returned by chat_info_defaults()

  • so if the plugin figures something out in there, we save it in our

own settings.

In the case of SIPE this adds a new setting, purple_uri, which can be
set with the ma-chan:// uri for a persistent chat.

This solves the issue with the SIPE plugin only knowing how to do name
lookups after doing 'chat list' - now it just needs to work once, and we
save the real URI in our settings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    ra04705b r1882b70  
    763763        struct groupchat *gc;
    764764        GList *info, *l;
     765        GString *missing_settings = NULL;
    765766
    766767        if (!pi->chat_info || !pi->chat_info_defaults ||
     
    788789                } else if (strcmp(pce->identifier, "passwd") == 0) {
    789790                        g_hash_table_replace(chat_hash, "passwd", g_strdup(password));
     791                } else {
     792                        char *key, *value;
     793
     794                        key = g_strdup_printf("purple_%s", pce->identifier);
     795                        str_reject_chars(key, " -", '_');
     796
     797                        if ((value = set_getstr(sets, key))) {
     798                                /* sync from bitlbee to the prpl */
     799                                g_hash_table_replace(chat_hash, (char *) pce->identifier, g_strdup(value));
     800                        } else if ((value = g_hash_table_lookup(chat_hash, pce->identifier))) {
     801                                /* if the bitlbee one was empty, sync from prpl to bitlbee */
     802                                set_setstr(sets, key, value);
     803                        }
     804
     805                        g_free(key);
     806                }
     807
     808                if (pce->required && !g_hash_table_lookup(chat_hash, pce->identifier)) {
     809                        if (!missing_settings) {
     810                                missing_settings = g_string_new(NULL);
     811                                g_string_printf(missing_settings,
     812                                        "Can't join %s. The following settings are required: ", room);
     813                        }
     814                        g_string_append_printf(missing_settings, "%s, ", pce->identifier);
    790815                }
    791816
     
    794819
    795820        g_list_free(info);
     821
     822        if (missing_settings) {
     823                /* remove the ", " from the end */
     824                g_string_truncate(missing_settings, missing_settings->len - 2);
     825
     826                imcb_error(ic, missing_settings->str);
     827
     828                g_string_free(missing_settings, TRUE);
     829                g_hash_table_destroy(chat_hash);
     830                return NULL;
     831        }
    796832
    797833        /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */
     
    828864                purple_roomlist_ref(list);
    829865        }
     866}
     867
     868/* handles either prpl->chat_(add|free)_settings depending on the value of 'add' */
     869static void purple_chat_update_settings(account_t *acc, set_t **head, gboolean add)
     870{
     871        PurplePlugin *prpl = purple_plugins_find_with_id((char *) acc->prpl->data);
     872        PurplePluginProtocolInfo *pi = prpl->info->extra_info;
     873        GList *info, *l;
     874
     875        if (!pi->chat_info || !pi->chat_info_defaults) {
     876                return;
     877        }
     878
     879        /* hack / leap of faith: pass a NULL here because we don't have a connection yet.
     880         * i reviewed all the built-in prpls and a bunch of third-party ones and none
     881         * of them seem to need this parameter at all, so... i hope it never crashes */
     882        info = pi->chat_info(NULL);
     883
     884        for (l = info; l; l = l->next) {
     885                struct proto_chat_entry *pce = l->data;
     886                char *key;
     887
     888                if (strcmp(pce->identifier, "handle") == 0 ||
     889                    strcmp(pce->identifier, "password") == 0 ||
     890                    strcmp(pce->identifier, "passwd") == 0) {
     891                        /* skip these, they are handled above */
     892                        g_free(pce);
     893                        continue;
     894                }
     895
     896                key = g_strdup_printf("purple_%s", pce->identifier);
     897                str_reject_chars(key, " -", '_');
     898
     899                if (add) {
     900                        set_add(head, key, NULL, NULL, NULL);
     901                } else {
     902                        set_del(head, key);
     903                }
     904
     905                g_free(key);
     906                g_free(pce);
     907        }
     908
     909        g_list_free(NULL);
     910        g_list_free(info);
     911}
     912
     913static void purple_chat_add_settings(account_t *acc, set_t **head)
     914{
     915        purple_chat_update_settings(acc, head, TRUE);
     916}
     917
     918static void purple_chat_free_settings(account_t *acc, set_t **head)
     919{
     920        purple_chat_update_settings(acc, head, FALSE);
    830921}
    831922
     
    17671858        funcs.chat_join = purple_chat_join;
    17681859        funcs.chat_list = purple_chat_list;
     1860        funcs.chat_add_settings = purple_chat_add_settings;
     1861        funcs.chat_free_settings = purple_chat_free_settings;
    17691862        funcs.transfer_request = purple_transfer_request;
    17701863
Note: See TracChangeset for help on using the changeset viewer.