Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r977a9d5 r9076a1c  
    9090
    9191GList *protocols = NULL;
    92 GList *disabled_protocols = NULL;
    9392
    9493void register_protocol(struct prpl *p)
     
    104103
    105104        if (refused) {
    106                 disabled_protocols = g_list_append(disabled_protocols, p);
     105                log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name);
    107106        } else {
    108107                protocols = g_list_append(protocols, p);
     
    110109}
    111110
    112 static 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 
    118111struct prpl *find_protocol(const char *name)
    119112{
    120         GList *gl = g_list_find_custom(protocols, name, proto_name_cmp);
    121         return gl ? gl->data: NULL;
    122 }
    123 
    124 gboolean is_protocol_disabled(const char *name)
    125 {
    126         return g_list_find_custom(disabled_protocols, name, proto_name_cmp) != NULL;
     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;
    127124}
    128125
     
    135132        extern void twitter_initmodule();
    136133        extern void purple_initmodule();
     134        extern void rpc_initmodule();
    137135
    138136#ifdef WITH_MSN
     
    158156#ifdef WITH_PURPLE
    159157        purple_initmodule();
     158#endif
     159
     160#ifdef WITH_RPC
     161        rpc_initmodule();
    160162#endif
    161163
     
    207209        account_t *a;
    208210
    209         if (!ic->bee->ui->log) {
    210                 return;
    211         }
    212 
    213211        va_start(params, format);
    214212        text = g_strdup_vprintf(format, params);
     
    229227        /* If we found one, include the screenname in the message. */
    230228        if (a) {
    231                 ic->bee->ui->log(ic->bee, ic->acc->tag, text);
     229                /* FIXME(wilmer): ui_log callback or so */
     230                irc_rootmsg(ic->bee->ui_data, "%s - %s", ic->acc->tag, text);
    232231        } else {
    233                 ic->bee->ui->log(ic->bee, ic->acc->prpl->name, text);
     232                irc_rootmsg(ic->bee->ui_data, "%s - %s", ic->acc->prpl->name, text);
    234233        }
    235234
     
    313312        }
    314313
    315         if (ic->acc->flags & ACC_FLAG_LOCAL) {
     314        if ((ic->acc->flags & ACC_FLAG_LOCAL_CONTACTS) &&
     315            !(ic->flags & OPT_LOCAL_CONTACTS_SENT) &&
     316            ic->acc->prpl->add_buddy) {
    316317                GHashTableIter nicks;
    317                 gpointer k, v;
     318                gpointer handle;
    318319                g_hash_table_iter_init(&nicks, ic->acc->nicks);
    319                 while (g_hash_table_iter_next(&nicks, &k, &v)) {
    320                         ic->acc->prpl->add_buddy(ic, (char *) k, NULL);
     320                while (g_hash_table_iter_next(&nicks, &handle, NULL)) {
     321                        ic->acc->prpl->add_buddy(ic, (char *) handle, NULL);
    321322                }
    322323        }
     
    413414        query_del_by_conn((irc_t *) ic->bee->ui_data, ic);
    414415
     416        /* Throw away groupchats owned by this account. Historically this was only
     417           ever done by IM modules which is a bug. But it gives them opportunity
     418           to clean up protocol-specific bits as well so keep it that way, just
     419           do another cleanup here as a fallback. Don't want to leave any dangling
     420           pointers! */
     421        while (ic->groupchats) {
     422                imcb_chat_free(ic->groupchats->data);
     423        }
     424
    415425        if (!a) {
    416426                /* Uhm... This is very sick. */
     
    498508}
    499509
     510/* Returns the local contacts for an IM account (based on assigned nicks).
     511   Linked list should be freed, the strings themselves not! So look at it
     512   like a GSList<const char*> I guess? Empty list means NULL retval (as
     513   always with GSList). */
     514GSList *imcb_get_local_contacts(struct im_connection *ic)
     515{
     516        GHashTableIter nicks;
     517        GSList *ret = NULL;
     518       
     519        if (!(ic->acc->flags & ACC_FLAG_LOCAL_CONTACTS)) {
     520                /* Only allow protocols that indicate local contact list
     521                   support to use this function. */
     522                return ret;
     523        }
     524       
     525        g_hash_table_iter_init(&nicks, ic->acc->nicks);
     526        gpointer handle;
     527        while (g_hash_table_iter_next(&nicks, &handle, NULL)) {
     528                ret = g_slist_prepend(ret, (char *) handle);
     529        }
     530       
     531        /* If the protocol asked for the list, assume we won't have to send it
     532           anymore in imcb_connected(). */
     533        ic->flags |= OPT_LOCAL_CONTACTS_SENT;
     534       
     535        return ret;
     536}
     537
    500538
    501539struct imcb_ask_cb_data {
     
    556594        struct imcb_ask_cb_data *cbd = data;
    557595
    558         cbd->ic->acc->prpl->add_buddy(cbd->ic, cbd->handle, NULL);
     596        if (cbd->ic->acc->prpl->add_buddy) {
     597                cbd->ic->acc->prpl->add_buddy(cbd->ic, cbd->handle, NULL);
     598        }
    559599
    560600        imcb_ask_cb_free(data);
     
    622662                GList *m = ic->acc->prpl->away_states(ic);
    623663                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
    624                 away = imc_away_state_find(m, away, &msg) ? :
    625                        (imc_away_state_find(m, "away", &msg) ? : m->data);
     664                away = imc_away_state_find(m, away, &msg) ? : m->data;
    626665        } else if (ic->acc->flags & ACC_FLAG_STATUS_MESSAGE) {
    627666                away = NULL;
     
    742781}
    743782
    744 /* Deprecated: using this function resulted in merging several handles accidentally
    745  * Also the irc layer handles this decently nowadays */
    746783void imcb_clean_handle(struct im_connection *ic, char *handle)
    747784{
    748 }
     785        /* Accepts a handle and does whatever is necessary to make it
     786           BitlBee-friendly. Currently this means removing everything
     787           outside 33-127 (ASCII printable excl spaces), @ (only one
     788           is allowed) and ! and : */
     789        char out[strlen(handle) + 1];
     790        int s, d;
     791
     792        s = d = 0;
     793        while (handle[s]) {
     794                if (handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' &&
     795                    (handle[s] & 0x80) == 0) {
     796                        if (handle[s] == '@') {
     797                                /* See if we got an @ already? */
     798                                out[d] = 0;
     799                                if (strchr(out, '@')) {
     800                                        continue;
     801                                }
     802                        }
     803
     804                        out[d++] = handle[s];
     805                }
     806                s++;
     807        }
     808        out[d] = handle[s];
     809
     810        strcpy(handle, out);
     811}
Note: See TracChangeset for help on using the changeset viewer.