Changeset ad9ac5d


Ignore:
Timestamp:
2015-11-23T21:20:34Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
1e2094e, 5b01e1a
Parents:
9c8dbc7
Message:

Show a nicer message when a protocol is disabled in account add

This adds the disabled protocols' prpl structs to a different linked
list, only used for this lookup. They were previously marked as leaking
by valgrind, so, whatever. I can't free them, since some protocols
memdup() it after attempting to register.

I think disabling the protocols from bitlbee.conf is just stupid and
provides no real benefits, but someone will complain if i get rid of it.
So this just improves the error message to make it less confusing when
someone accidentally uncomments that crap.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r9c8dbc7 rad9ac5d  
    9090
    9191GList *protocols = NULL;
     92GList *disabled_protocols = NULL;
    9293
    9394void register_protocol(struct prpl *p)
     
    103104
    104105        if (refused) {
    105                 log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name);
     106                disabled_protocols = g_list_append(disabled_protocols, p);
    106107        } else {
    107108                protocols = g_list_append(protocols, p);
     
    109110}
    110111
     112static int proto_name_cmp(const void *proto_, const void *name)
     113{
     114        const struct prpl *proto = proto_;
     115        return g_strcasecmp(proto->name, name);
     116}
     117
    111118struct prpl *find_protocol(const char *name)
    112119{
    113         GList *gl;
    114 
    115         for (gl = protocols; gl; gl = gl->next) {
    116                 struct prpl *proto = gl->data;
    117 
    118                 if (g_strcasecmp(proto->name, name) == 0) {
    119                         return proto;
    120                 }
    121         }
    122 
    123         return NULL;
     120        GList *gl = g_list_find_custom(protocols, name, proto_name_cmp);
     121        return gl ? gl->data: NULL;
     122}
     123
     124gboolean is_protocol_disabled(const char *name)
     125{
     126        return g_list_find_custom(disabled_protocols, name, proto_name_cmp) != NULL;
    124127}
    125128
  • protocols/nogaim.h

    r9c8dbc7 rad9ac5d  
    275275G_MODULE_EXPORT GSList *get_connections();
    276276G_MODULE_EXPORT struct prpl *find_protocol(const char *name);
     277G_MODULE_EXPORT gboolean is_protocol_disabled(const char *name);
    277278/* When registering a new protocol, you should allocate space for a new prpl
    278279 * struct, initialize it (set the function pointers to point to your
  • root_commands.c

    r9c8dbc7 rad9ac5d  
    425425
    426426                if (prpl == NULL) {
    427                         irc_rootmsg(irc, "Unknown protocol");
     427                        if (is_protocol_disabled(cmd[2])) {
     428                                irc_rootmsg(irc, "Protocol disabled in global config");
     429                        } else {
     430                                irc_rootmsg(irc, "Unknown protocol");
     431                        }
    428432                        return;
    429433                }
Note: See TracChangeset for help on using the changeset viewer.