Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    ra9e0de2 r9f03c47  
    114114}
    115115
    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 
    140116static void purple_init(account_t *acc)
    141117{
     
    305281        }
    306282
    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 
    312283        /* Go through all away states to figure out if away/status messages
    313284           are possible. */
     
    368339                purple_account_set_check_mail(pa, set_getbool(&acc->set, "mail_notifications"));
    369340        }
    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         }
    375341}
    376342
     
    401367        purple_account_set_password(pd->account, acc->pass);
    402368        purple_sync_settings(acc, pd->account);
    403 
    404         if (purple_account_should_set_nick(acc)) {
    405                 pd->flags = PURPLE_OPT_SHOULD_SET_NICK;
    406         }
    407369
    408370        purple_account_set_enabled(pd->account, "BitlBee", TRUE);
     
    774736        struct groupchat *gc;
    775737        GList *info, *l;
    776         GString *missing_settings = NULL;
    777738
    778739        if (!pi->chat_info || !pi->chat_info_defaults ||
     
    800761                } else if (strcmp(pce->identifier, "passwd") == 0) {
    801762                        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);
    824763                }
    825764
     
    828767
    829768        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         }
    841769
    842770        /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */
     
    873801                purple_roomlist_ref(list);
    874802        }
    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);
    930803}
    931804
     
    966839{
    967840        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;
    970842        set_t *s;
    971843
     
    980852        // user list needs to be requested for Gadu-Gadu
    981853        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         }
    989854
    990855        ic->flags |= OPT_DOES_HTML;
     
    1038903                PurpleGroup *group = purple_buddy_get_group(bud);
    1039904                struct im_connection *ic = purple_ic_by_pa(bud->account);
    1040                 struct purple_data *pd = ic->proto_data;
    1041905                PurpleStatus *as;
    1042906                int flags = 0;
    1043                 char *alias = NULL;
    1044907
    1045908                if (ic == NULL) {
     
    1047910                }
    1048911
    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);
    1056916                }
    1057917
     
    11971057}
    11981058
    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 */
    12041060static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime)
    12051061{
    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);
    12081064        }
    12091065}
     
    15311387}
    15321388
    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 
    15471389static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room)
    15481390{
    15491391        bee_chat_info_t *ci;
    1550         char *title;
     1392        const char *title;
    15511393        const char *topic;
    15521394        GList *fields;
     
    15541396
    15551397        fields = purple_roomlist_room_get_fields(room);
    1556         title = prplcb_roomlist_get_room_name(list, room);
     1398        title = purple_roomlist_room_get_name(room);
    15571399
    15581400        if (rld->topic >= 0) {
     
    15631405
    15641406        ci = g_new(bee_chat_info_t, 1);
    1565         ci->title = title;
     1407        ci->title = g_strdup(title);
    15661408        ci->topic = g_strdup(topic);
    15671409        rld->chats = g_slist_prepend(rld->chats, ci);
     
    17851627}
    17861628
    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 
    17911629void purple_initmodule()
    17921630{
     
    17951633        GString *help;
    17961634        char *dir;
    1797         gboolean debug_enabled = !!getenv("BITLBEE_DEBUG");
    17981635
    17991636        if (purple_get_core() != NULL) {
     
    18031640        }
    18041641
    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);
    18071644
    18081645        dir = g_strdup_printf("%s/purple", global.conf->configdir);
     
    18141651        g_free(dir);
    18151652
    1816         purple_debug_set_enabled(debug_enabled);
     1653        purple_debug_set_enabled(FALSE);
    18171654        purple_core_set_ui_ops(&bee_core_uiops);
    18181655        purple_eventloop_set_ui_ops(&glib_eventloops);
     
    18221659                abort();
    18231660        }
    1824         purple_debug_set_enabled(FALSE);
    18251661
    18261662        if (proxytype != PROXY_NONE) {
     
    18811717        funcs.chat_join = purple_chat_join;
    18821718        funcs.chat_list = purple_chat_list;
    1883         funcs.chat_add_settings = purple_chat_add_settings;
    1884         funcs.chat_free_settings = purple_chat_free_settings;
    18851719        funcs.transfer_request = purple_transfer_request;
    18861720
     
    18931727                PurplePluginProtocolInfo *pi = prot->info->extra_info;
    18941728                struct prpl *ret;
    1895                 struct plugin_info *info;
    18961729
    18971730                /* If we already have this one (as a native module), don't
     
    19281761                        register_protocol(ret);
    19291762                }
    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);
    19401763        }
    19411764
Note: See TracChangeset for help on using the changeset viewer.