Changeset 5a8afc3 for storage_xml.c


Ignore:
Timestamp:
2016-11-21T06:58:47Z (7 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
3f44e43, f8c9347
Parents:
11d4123
git-author:
dequis <dx@…> (21-11-16 06:40:54)
git-committer:
dequis <dx@…> (21-11-16 06:58:47)
Message:

Manual merge with wilmer's approach to handling missing protocols

Turns out he already implemented pretty much the same thing in the
parson branch... last year.

The differences between the two approaches are subtle (there aren't too
many ways to do this, some lines are the exact same thing) but I decided
I like his version better, so this mostly reverts a handful of my
changes while keeping others. The main advantage of his approach is that
no fake protocols are registered, no actual prpl functions are called,
and the missing prpl is a singleton constant.

New things compared to the implementation in the other branch:

  • The explain_unknown_protocol() function.
  • Fixed named chatrooms throwing a warning and losing the "account" setting when saving. See changes in irc_im.c
  • Fixed the "server" setting dropping when saving. See account.c

Differences with my previous implementation:

  • Accounts with missing protocols don't autoconnect
  • 'account list' marks them as "(missing!)"
File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r11d4123 r5a8afc3  
    6060}
    6161
    62 static void handle_settings(struct xt_node *node, set_t **head, gboolean add_unknowns)
     62static void handle_settings(struct xt_node *node, set_t **head)
    6363{
    6464        struct xt_node *c;
     
    7070
    7171                if (!name) {
    72                         continue;
    73                 }
    74 
    75                 if (add_unknowns && !set_find(head, name)) {
    76                         s = set_add(head, name, NULL, NULL, NULL);
    77                         s->flags |= ACC_SET_ONLINE_ONLY;
    78                         s->value = g_strdup(c->text);
    7972                        continue;
    8073                }
     
    9386                        }
    9487                }
     88        }
     89}
     90
     91/* Use for unsupported/not-found protocols. Save settings as-is but don't allow changes. */
     92static void handle_settings_raw(struct xt_node *node, set_t **head)
     93{
     94        struct xt_node *c;
     95
     96        for (c = node->children; (c = xt_find_node(c, "setting")); c = c->next) {
     97                char *name = xt_find_attr(c, "name");
     98
     99                if (!name) {
     100                        continue;
     101                }
     102
     103                set_t *s = set_add(head, name, NULL, NULL, NULL);
     104                set_setstr(head, name, c->text);
     105                s->flags |= SET_HIDDEN |
     106                            ACC_SET_OFFLINE_ONLY | ACC_SET_ONLINE_ONLY;
    95107        }
    96108}
     
    106118        account_t *acc;
    107119        struct xt_node *c;
    108         gboolean is_unknown = FALSE;
    109120
    110121        handle = xt_find_attr(node, "handle");
     
    120131                if (!prpl) {
    121132                        irc_rootmsg(xd->irc, "Warning: Protocol not found: `%s'", protocol);
    122                         prpl = make_unknown_protocol(protocol);
    123                 }
    124                 is_unknown = (prpl->options & PRPL_OPT_UNKNOWN_PROTOCOL) != 0;
     133                        prpl = (struct prpl*) &protocol_missing;
     134                }
    125135                local = protocol_account_islocal(protocol);
    126136        }
     
    158168                acc->flags |= ACC_FLAG_LOCKED;
    159169        }
     170        if (prpl == &protocol_missing) {
     171                set_t *s = set_add(&acc->set, "_protocol_name", protocol, NULL, NULL);
     172                s->flags |= SET_HIDDEN | SET_NOSAVE |
     173                            ACC_SET_OFFLINE_ONLY | ACC_SET_ONLINE_ONLY;
     174        }
    160175
    161176        g_free(pass_cr);
    162177        g_free(password);
    163178
    164         handle_settings(node, &acc->set, is_unknown);
     179        if (prpl == &protocol_missing) {
     180                handle_settings_raw(node, &acc->set);
     181        } else {
     182                handle_settings(node, &acc->set);
     183        }
    165184
    166185        for (c = node->children; (c = xt_find_node(c, "buddy")); c = c->next) {
     
    201220        }
    202221
    203         handle_settings(node, &ic->set, FALSE);
     222        handle_settings(node, &ic->set);
    204223
    205224        return XT_HANDLED;
     
    279298        }
    280299
    281         handle_settings(node, &xd->irc->b->set, FALSE);
     300        handle_settings(node, &xd->irc->b->set);
    282301
    283302error:
     
    351370
    352371                cur = xt_new_node("account", NULL, NULL);
    353                 xt_add_attr(cur, "protocol", acc->prpl->name);
     372                if (acc->prpl == &protocol_missing) {
     373                        xt_add_attr(cur, "protocol", set_getstr(&acc->set, "_protocol_name"));
     374                } else {
     375                        xt_add_attr(cur, "protocol", acc->prpl->name);
     376                }
    354377                xt_add_attr(cur, "handle", acc->user);
    355378                xt_add_attr(cur, "password", pass_b64);
Note: See TracChangeset for help on using the changeset viewer.