Changeset ad2d8bc for otr.c


Ignore:
Timestamp:
2010-08-25T23:03:11Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
8358691
Parents:
be999a5
Message:

It compiles, including otr.c. Time to hook it up with the rest again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • otr.c

    rbe999a5 rad2d8bc  
    146146int hexval(char a);
    147147
    148 /* determine the user_t for a given handle/protocol pair
     148/* determine the irc_user_t for a given handle/protocol pair
    149149   returns NULL if not found */
    150 user_t *peeruser(irc_t *irc, const char *handle, const char *protocol);
     150irc_user_t *peeruser(irc_t *irc, const char *handle, const char *protocol);
    151151
    152152/* handle SMP TLVs from a received message */
     
    156156   returns 0 if neither op_buddies nor voice_buddies is set to "encrypted",
    157157   i.e. msgstate should be announced seperately */
    158 int otr_update_modeflags(irc_t *irc, user_t *u);
     158int otr_update_modeflags(irc_t *irc, irc_user_t *u);
    159159
    160160/* show general info about the OTR subsystem; called by 'otr info' */
     
    238238        int kg=0;
    239239
    240         g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, irc->nick);
     240        g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, irc->user->nick);
    241241        e = otrl_privkey_read(irc->otr->us, s);
    242242        if(e && e!=enoent) {
    243243                irc_usermsg(irc, "otr load: %s: %s", s, gcry_strerror(e));
    244244        }
    245         g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->nick);
     245        g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick);
    246246        e = otrl_privkey_read_fingerprints(irc->otr->us, s, NULL, NULL);
    247247        if(e && e!=enoent) {
     
    250250       
    251251        /* check for otr keys on all accounts */
    252         for(a=irc->accounts; a; a=a->next) {
     252        for(a=irc->b->accounts; a; a=a->next) {
    253253                kg = otr_check_for_key(a) || kg;
    254254        }
     
    269269        gcry_error_t e;
    270270
    271         g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->nick);
     271        g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick);
    272272        e = otrl_privkey_write_fingerprints(irc->otr->us, s);
    273273        if(e) {
     
    301301int otr_check_for_key(account_t *a)
    302302{
    303         irc_t *irc = a->irc;
     303        irc_t *irc = a->bee->ui_data;
    304304        OtrlPrivKey *k;
    305305       
     
    329329        OtrlTLV *tlvs = NULL;
    330330        char *colormsg;
     331        irc_t *irc = ic->bee->ui_data;
    331332       
    332333        /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */
     
    335336        }
    336337       
    337         ignore_msg = otrl_message_receiving(ic->irc->otr->us, &global.otr_ops, ic,
     338        ignore_msg = otrl_message_receiving(irc->otr->us, &global.otr_ops, ic,
    338339                ic->acc->user, ic->acc->prpl->name, handle, msg, &newmsg,
    339340                &tlvs, NULL, NULL);
     
    349350        } else {
    350351                /* OTR has processed this message */
    351                 ConnContext *context = otrl_context_find(ic->irc->otr->us, handle,
     352                ConnContext *context = otrl_context_find(irc->otr->us, handle,
    352353                        ic->acc->user, ic->acc->prpl->name, 0, NULL, NULL, NULL);
    353354                if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
    354                    set_getbool(&ic->irc->set, "color_encrypted")) {
     355                   set_getbool(&ic->bee->set, "color_encrypted")) {
    355356                        /* color according to f'print trust */
    356357                        int color;
     
    381382        char *otrmsg = NULL;
    382383        ConnContext *ctx = NULL;
     384        irc_t *irc = ic->bee->ui_data;
    383385
    384386        /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */
    385387        if(ic->acc->prpl->options & OPT_NOOTR) {
    386                 return (ic->acc->prpl->buddy_msg(ic, handle, msg, flags));
    387         }
    388        
    389         st = otrl_message_sending(ic->irc->otr->us, &global.otr_ops, ic,
     388                /* TODO(wilmer): const */
     389                return (ic->acc->prpl->buddy_msg(ic, (char*) handle, (char*) msg, flags));
     390        }
     391       
     392        st = otrl_message_sending(irc->otr->us, &global.otr_ops, ic,
    390393                ic->acc->user, ic->acc->prpl->name, handle,
    391394                msg, NULL, &otrmsg, NULL, NULL);
     
    394397        }
    395398
    396         ctx = otrl_context_find(ic->irc->otr->us,
     399        ctx = otrl_context_find(irc->otr->us,
    397400                        handle, ic->acc->user, ic->acc->prpl->name,
    398401                        1, NULL, NULL, NULL);
     
    451454{
    452455        struct im_connection *ic = check_imc(opdata, context->accountname, context->protocol);
     456        irc_t *irc = ic->bee->ui_data;
    453457        const char *p;
    454458       
    455459        /* policy override during keygen: if we're missing the key for context but are currently
    456460           generating it, then that's as much as we can do. => temporarily return NEVER. */
    457         if(keygen_in_progress(ic->irc, context->accountname, context->protocol) &&
    458            !otrl_privkey_find(ic->irc->otr->us, context->accountname, context->protocol))
     461        if(keygen_in_progress(irc, context->accountname, context->protocol) &&
     462           !otrl_privkey_find(irc->otr->us, context->accountname, context->protocol))
    459463                return OTRL_POLICY_NEVER;
    460464
    461         p = set_getstr(&ic->irc->set, "otr_policy");
     465        p = set_getstr(&ic->bee->set, "otr_policy");
    462466        if(!strcmp(p, "never"))
    463467                return OTRL_POLICY_NEVER;
     
    476480{
    477481        struct im_connection *ic = check_imc(opdata, accountname, protocol);
     482        irc_t *irc = ic->bee->ui_data;
    478483       
    479484        /* will fail silently if keygen already in progress */
    480         otr_keygen(ic->irc, accountname, protocol);
     485        otr_keygen(irc, accountname, protocol);
    481486}
    482487
     
    485490{
    486491        struct im_connection *ic = check_imc(opdata, accountname, protocol);
    487         user_t *u;
    488 
    489         /* lookup the user_t for the given recipient */
    490         u = user_findhandle(ic, recipient);
    491         if(u) {
    492                 if(u->online)
     492        bee_user_t *bu;
     493
     494        /* lookup the irc_user_t for the given recipient */
     495        bu = bee_user_by_handle(ic->bee, ic, recipient);
     496        if(bu) {
     497                if(bu->flags & BEE_USER_ONLINE)
    493498                        return 1;
    494499                else
     
    503508{
    504509        struct im_connection *ic = check_imc(opdata, accountname, protocol);
     510        irc_t *irc = ic->bee->ui_data;
    505511
    506512        if (strcmp(accountname, recipient) == 0) {
    507513                /* huh? injecting messages to myself? */
    508                 irc_usermsg(ic->irc, "note to self: %s", message);
     514                irc_usermsg(irc, "note to self: %s", message);
    509515        } else {
    510516                /* need to drop some consts here :-( */
     
    520526        struct im_connection *ic = check_imc(opdata, accountname, protocol);
    521527        char *msg = g_strdup(message);
     528        irc_t *irc = ic->bee->ui_data;
    522529
    523530        strip_html(msg);
    524         irc_usermsg(ic->irc, "otr: %s", msg);
     531        irc_usermsg(irc, "otr: %s", msg);
    525532
    526533        g_free(msg);
     
    533540{
    534541        struct im_connection *ic = check_imc(opdata, accountname, protocol);
     542        irc_t *irc = ic->bee->ui_data;
    535543        char hunam[45];         /* anybody looking? ;-) */
    536544       
    537545        otrl_privkey_hash_to_human(hunam, fingerprint);
    538         irc_usermsg(ic->irc, "new fingerprint for %s: %s",
    539                 peernick(ic->irc, username, protocol), hunam);
     546        irc_usermsg(irc, "new fingerprint for %s: %s",
     547                peernick(irc, username, protocol), hunam);
    540548}
    541549
     
    543551{
    544552        struct im_connection *ic = (struct im_connection *)opdata;
    545 
    546         otr_save(ic->irc);
     553        irc_t *irc = ic->bee->ui_data;
     554
     555        otr_save(irc);
    547556}
    548557
     
    551560        struct im_connection *ic =
    552561                check_imc(opdata, context->accountname, context->protocol);
    553         user_t *u;
     562        irc_user_t *u;
     563        irc_t *irc = ic->bee->ui_data;
    554564        const char *trust;
    555565
    556         u = peeruser(ic->irc, context->username, context->protocol);
     566        u = peeruser(irc, context->username, context->protocol);
    557567        if(!u) {
    558568                log_message(LOGLVL_ERROR,
    559                         "BUG: otr.c: op_gone_secure: user_t for %s/%s/%s not found!",
     569                        "BUG: otr.c: op_gone_secure: irc_user_t for %s/%s/%s not found!",
    560570                        context->username, context->protocol, context->accountname);
    561571                return;
     
    564574        trust = context->active_fingerprint->trust;
    565575        if(trust && trust[0])
    566                 u->encrypted = 2;
     576                u->flags |= IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED;
    567577        else
    568                 u->encrypted = 1;
    569         if(!otr_update_modeflags(ic->irc, u))
    570                 irc_usermsg(ic->irc, "conversation with %s is now off the record", u->nick);
     578                u->flags = ( u->flags & ~IRC_USER_OTR_TRUSTED ) | IRC_USER_OTR_ENCRYPTED;
     579        if(!otr_update_modeflags(irc, u))
     580                irc_usermsg(irc, "conversation with %s is now off the record", u->nick);
    571581}
    572582
     
    575585        struct im_connection *ic =
    576586                check_imc(opdata, context->accountname, context->protocol);
    577         user_t *u;
    578 
    579         u = peeruser(ic->irc, context->username, context->protocol);
     587        irc_t *irc = ic->bee->ui_data;
     588        irc_user_t *u;
     589
     590        u = peeruser(irc, context->username, context->protocol);
    580591        if(!u) {
    581592                log_message(LOGLVL_ERROR,
    582                         "BUG: otr.c: op_gone_insecure: user_t for %s/%s/%s not found!",
     593                        "BUG: otr.c: op_gone_insecure: irc_user_t for %s/%s/%s not found!",
    583594                        context->username, context->protocol, context->accountname);
    584595                return;
    585596        }
    586         u->encrypted = 0;
    587         if(!otr_update_modeflags(ic->irc, u))
    588                 irc_usermsg(ic->irc, "conversation with %s is now in the clear", u->nick);
     597        u->flags &= ~( IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED );
     598        if(!otr_update_modeflags(irc, u))
     599                irc_usermsg(irc, "conversation with %s is now in the clear", u->nick);
    589600}
    590601
     
    593604        struct im_connection *ic =
    594605                check_imc(opdata, context->accountname, context->protocol);
    595         user_t *u;
    596 
    597         u = peeruser(ic->irc, context->username, context->protocol);
     606        irc_t *irc = ic->bee->ui_data;
     607        irc_user_t *u;
     608
     609        u = peeruser(irc, context->username, context->protocol);
    598610        if(!u) {
    599611                log_message(LOGLVL_ERROR,
    600                         "BUG: otr.c: op_still_secure: user_t for %s/%s/%s not found!",
     612                        "BUG: otr.c: op_still_secure: irc_user_t for %s/%s/%s not found!",
    601613                        context->username, context->protocol, context->accountname);
    602614                return;
    603615        }
    604616        if(context->active_fingerprint->trust[0])
    605                 u->encrypted = 2;
     617                u->flags |= IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED;
    606618        else
    607                 u->encrypted = 1;
    608         if(!otr_update_modeflags(ic->irc, u))
    609                 irc_usermsg(ic->irc, "otr connection with %s has been refreshed", u->nick);
     619                u->flags = ( u->flags & ~IRC_USER_OTR_TRUSTED ) | IRC_USER_OTR_ENCRYPTED;
     620        if(!otr_update_modeflags(irc, u))
     621                irc_usermsg(irc, "otr connection with %s has been refreshed", u->nick);
    610622}
    611623
     
    630642{
    631643        struct im_connection *ic = (struct im_connection *)opdata;
    632 
    633         return peernick(ic->irc, account, protocol);
     644        irc_t *irc = ic->bee->ui_data;
     645
     646        return peernick(irc, account, protocol);
    634647}
    635648
     
    639652void cmd_otr_disconnect(irc_t *irc, char **args)
    640653{
    641         user_t *u;
    642 
    643         u = user_find(irc, args[1]);
    644         if(!u || !u->ic) {
     654        irc_user_t *u;
     655
     656        u = irc_user_by_name(irc, args[1]);
     657        if(!u || !u->bu || !u->bu->ic) {
    645658                irc_usermsg(irc, "%s: unknown user", args[1]);
    646659                return;
     
    648661       
    649662        otrl_message_disconnect(irc->otr->us, &global.otr_ops,
    650                 u->ic, u->ic->acc->user, u->ic->acc->prpl->name, u->handle);
     663                u->bu->ic, u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, u->bu->handle);
    651664       
    652665        /* for some reason, libotr (3.1.0) doesn't do this itself: */
    653         if(u->encrypted) {
     666        if(u->flags & IRC_USER_OTR_ENCRYPTED) {
    654667                ConnContext *ctx;
    655                 ctx = otrl_context_find(irc->otr->us, u->handle, u->ic->acc->user,
    656                         u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
     668                ctx = otrl_context_find(irc->otr->us, u->bu->handle, u->bu->ic->acc->user,
     669                        u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL);
    657670                if(ctx)
    658                         op_gone_insecure(u->ic, ctx);
     671                        op_gone_insecure(u->bu->ic, ctx);
    659672                else /* huh? */
    660                         u->encrypted = 0;
     673                        u->flags &= ( IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED );
    661674        }
    662675}
     
    664677void cmd_otr_connect(irc_t *irc, char **args)
    665678{
    666         user_t *u;
    667 
    668         u = user_find(irc, args[1]);
    669         if(!u || !u->ic) {
     679        irc_user_t *u;
     680
     681        u = irc_user_by_name(irc, args[1]);
     682        if(!u || !u->bu || !u->bu->ic) {
    670683                irc_usermsg(irc, "%s: unknown user", args[1]);
    671684                return;
    672685        }
    673         if(!u->online) {
     686        if(!(u->bu->flags & BEE_USER_ONLINE)) {
    674687                irc_usermsg(irc, "%s is offline", args[1]);
    675688                return;
    676689        }
    677690       
    678         imc_buddy_msg(u->ic, u->handle, "?OTR?", 0);
     691        /* TODO(wilmer): imc_buddy_msg(u->bu->ic, u->bu->handle, "?OTR?", 0); */
    679692}
    680693
    681694void cmd_otr_smp(irc_t *irc, char **args)
    682695{
    683         user_t *u;
     696        irc_user_t *u;
    684697        ConnContext *ctx;
    685698       
    686         u = user_find(irc, args[1]);
    687         if(!u || !u->ic) {
     699        u = irc_user_by_name(irc, args[1]);
     700        if(!u || !u->bu || !u->bu->ic) {
    688701                irc_usermsg(irc, "%s: unknown user", args[1]);
    689702                return;
    690703        }
    691         if(!u->online) {
     704        if(!(u->bu->flags & BEE_USER_ONLINE)) {
    692705                irc_usermsg(irc, "%s is offline", args[1]);
    693706                return;
    694707        }
    695708       
    696         ctx = otrl_context_find(irc->otr->us, u->handle,
    697                 u->ic->acc->user, u->ic->acc->prpl->name, 1, NULL, NULL, NULL);
     709        ctx = otrl_context_find(irc->otr->us, u->bu->handle,
     710                u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, 1, NULL, NULL, NULL);
    698711        if(!ctx) {
    699712                /* huh? out of memory or what? */
     
    705718                        "SMP already in phase %d, sending abort before reinitiating",
    706719                        ctx->smstate->nextExpected+1);
    707                 otrl_message_abort_smp(irc->otr->us, &global.otr_ops, u->ic, ctx);
     720                otrl_message_abort_smp(irc->otr->us, &global.otr_ops, u->bu->ic, ctx);
    708721                otrl_sm_state_free(ctx->smstate);
    709722        }
     
    714727                irc_usermsg(irc, "smp: initiating with %s...", u->nick);
    715728                otrl_message_initiate_smp(irc->otr->us, &global.otr_ops,
    716                         u->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
     729                        u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
    717730                /* smp is now in EXPECT2 */
    718731        } else {
     
    721734                irc_usermsg(irc, "smp: responding to %s...", u->nick);
    722735                otrl_message_respond_smp(irc->otr->us, &global.otr_ops,
    723                         u->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
     736                        u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
    724737                /* smp is now in EXPECT3 */
    725738        }
     
    728741void cmd_otr_trust(irc_t *irc, char **args)
    729742{
    730         user_t *u;
     743        irc_user_t *u;
    731744        ConnContext *ctx;
    732745        unsigned char raw[20];
     
    734747        int i,j;
    735748       
    736         u = user_find(irc, args[1]);
    737         if(!u || !u->ic) {
     749        u = irc_user_by_name(irc, args[1]);
     750        if(!u || !u->bu || !u->bu->ic) {
    738751                irc_usermsg(irc, "%s: unknown user", args[1]);
    739752                return;
    740753        }
    741754       
    742         ctx = otrl_context_find(irc->otr->us, u->handle,
    743                 u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
     755        ctx = otrl_context_find(irc->otr->us, u->bu->handle,
     756                u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL);
    744757        if(!ctx) {
    745758                irc_usermsg(irc, "%s: no otr context with user", args[1]);
     
    780793                otrl_context_set_trust(fp, trust);
    781794                irc_usermsg(irc, "fingerprint match, trust set to \"%s\"", trust);
    782                 if(u->encrypted)
    783                         u->encrypted = 2;
     795                if(u->flags & IRC_USER_OTR_ENCRYPTED)
     796                        u->flags |= IRC_USER_OTR_TRUSTED;
    784797                otr_update_modeflags(irc, u);
    785798        }
     
    812825                        }
    813826                } else {
    814                         user_t *u = user_find(irc, args[1]);
    815                         if(!u || !u->ic) {
     827                        irc_user_t *u = irc_user_by_name(irc, args[1]);
     828                        if(!u || !u->bu || !u->bu->ic) {
    816829                                irc_usermsg(irc, "%s: unknown user", args[1]);
    817830                                g_free(arg);
    818831                                return;
    819832                        }
    820                         ctx = otrl_context_find(irc->otr->us, u->handle, u->ic->acc->user,
    821                                 u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
     833                        ctx = otrl_context_find(irc->otr->us, u->bu->handle, u->bu->ic->acc->user,
     834                                u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL);
    822835                        if(!ctx) {
    823836                                irc_usermsg(irc, "no otr context with %s", args[1]);
     
    848861        }
    849862       
    850         a = irc->accounts;
     863        a = irc->b->accounts;
    851864        for(i=0; i<n && a; i++, a=a->next);
    852865        if(!a) {
     
    862875        if(otrl_privkey_find(irc->otr->us, a->user, a->prpl->name)) {
    863876                char *s = g_strdup_printf("account %d already has a key, replace it?", n);
    864                 query_add(irc, NULL, s, yes_keygen, NULL, a);
     877                query_add(irc, NULL, s, yes_keygen, NULL, NULL, a);
    865878                g_free(s);
    866879        } else {
     
    918931        if(!strcmp(args[1], "fingerprint"))
    919932        {
    920                 user_t *u;
     933                irc_user_t *u;
    921934                ConnContext *ctx;
    922935                Fingerprint *fp;
     
    931944               
    932945                /* TODO: allow context specs ("user/proto/account") in 'otr forget fingerprint'? */
    933                 u = user_find(irc, args[2]);
    934                 if(!u || !u->ic) {
     946                u = irc_user_by_name(irc, args[2]);
     947                if(!u || !u->bu || !u->bu->ic) {
    935948                        irc_usermsg(irc, "%s: unknown user", args[2]);
    936949                        return;
    937950                }
    938951               
    939                 ctx = otrl_context_find(irc->otr->us, u->handle, u->ic->acc->user,
    940                         u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
     952                ctx = otrl_context_find(irc->otr->us, u->bu->handle, u->bu->ic->acc->user,
     953                        u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL);
    941954                if(!ctx) {
    942955                        irc_usermsg(irc, "no otr context with %s", args[2]);
     
    962975                p->fst = irc;
    963976                p->snd = fp;
    964                 query_add(irc, NULL, s, yes_forget_fingerprint, NULL, p);
     977                query_add(irc, NULL, s, yes_forget_fingerprint, NULL, NULL, p);
    965978                g_free(s);
    966979        }
     
    968981        else if(!strcmp(args[1], "context"))
    969982        {
    970                 user_t *u;
     983                irc_user_t *u;
    971984                ConnContext *ctx;
    972985                char *s;
     
    974987               
    975988                /* TODO: allow context specs ("user/proto/account") in 'otr forget contex'? */
    976                 u = user_find(irc, args[2]);
    977                 if(!u || !u->ic) {
     989                u = irc_user_by_name(irc, args[2]);
     990                if(!u || !u->bu || !u->bu->ic) {
    978991                        irc_usermsg(irc, "%s: unknown user", args[2]);
    979992                        return;
    980993                }
    981994               
    982                 ctx = otrl_context_find(irc->otr->us, u->handle, u->ic->acc->user,
    983                         u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
     995                ctx = otrl_context_find(irc->otr->us, u->bu->handle, u->bu->ic->acc->user,
     996                        u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL);
    984997                if(!ctx) {
    985998                        irc_usermsg(irc, "no otr context with %s", args[2]);
     
    9981011                p->fst = irc;
    9991012                p->snd = ctx;
    1000                 query_add(irc, NULL, s, yes_forget_context, NULL, p);
     1013                query_add(irc, NULL, s, yes_forget_context, NULL, NULL, p);
    10011014                g_free(s);
    10021015        }
     
    10151028                s = g_strdup_printf("about to forget the private key for %s/%s, are you sure?",
    10161029                        key->accountname, key->protocol);
    1017                 query_add(irc, NULL, s, yes_forget_key, NULL, key);
     1030                query_add(irc, NULL, s, yes_forget_key, NULL, NULL, key);
    10181031                g_free(s);
    10191032        }
     
    10321045void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs)
    10331046{
    1034         irc_t *irc = ic->irc;
     1047        irc_t *irc = ic->bee->ui_data;
    10351048        OtrlUserState us = irc->otr->us;
    10361049        OtrlMessageAppOps *ops = &global.otr_ops;
     
    10381051        ConnContext *context;
    10391052        NextExpectedSMP nextMsg;
    1040         user_t *u;
    1041 
    1042         u = user_findhandle(ic, handle);
    1043         if(!u) return;
     1053        irc_user_t *u;
     1054        bee_user_t *bu;
     1055
     1056        bu = bee_user_by_handle(ic->bee, ic, handle);
     1057        if(!bu || !(u = bu->ui_data)) return;
    10441058        context = otrl_context_find(us, handle,
    10451059                ic->acc->user, ic->acc->prpl->name, 1, NULL, NULL, NULL);
     
    10541068                if (nextMsg != OTRL_SMP_EXPECT1) {
    10551069                        irc_usermsg(irc, "smp %s: spurious SMP1 received, aborting", u->nick);
    1056                         otrl_message_abort_smp(us, ops, u->ic, context);
     1070                        otrl_message_abort_smp(us, ops, u->bu->ic, context);
    10571071                        otrl_sm_state_free(context->smstate);
    10581072                } else {
     
    10671081                if (nextMsg != OTRL_SMP_EXPECT2) {
    10681082                        irc_usermsg(irc, "smp %s: spurious SMP2 received, aborting", u->nick);
    1069                         otrl_message_abort_smp(us, ops, u->ic, context);
     1083                        otrl_message_abort_smp(us, ops, u->bu->ic, context);
    10701084                        otrl_sm_state_free(context->smstate);
    10711085                } else {
     
    10781092                if (nextMsg != OTRL_SMP_EXPECT3) {
    10791093                        irc_usermsg(irc, "smp %s: spurious SMP3 received, aborting", u->nick);
    1080                         otrl_message_abort_smp(us, ops, u->ic, context);
     1094                        otrl_message_abort_smp(us, ops, u->bu->ic, context);
    10811095                        otrl_sm_state_free(context->smstate);
    10821096                } else {
     
    10981112                if (nextMsg != OTRL_SMP_EXPECT4) {
    10991113                        irc_usermsg(irc, "smp %s: spurious SMP4 received, aborting", u->nick);
    1100                         otrl_message_abort_smp(us, ops, u->ic, context);
     1114                        otrl_message_abort_smp(us, ops, u->bu->ic, context);
    11011115                        otrl_sm_state_free(context->smstate);
    11021116                } else {
     
    11431157}
    11441158
    1145 user_t *peeruser(irc_t *irc, const char *handle, const char *protocol)
    1146 {
    1147         user_t *u;
    1148        
    1149         for(u=irc->users; u; u=u->next) {
     1159irc_user_t *peeruser(irc_t *irc, const char *handle, const char *protocol)
     1160{
     1161        GSList *l;
     1162       
     1163        for(l=irc->b->users; l; l = l->next) {
     1164                bee_user_t *bu = l->data;
    11501165                struct prpl *prpl;
    1151                 if(!u->ic || !u->handle)
     1166                if(!bu->ui_data || !bu->ic || !bu->handle)
    11521167                        continue;
    1153                 prpl = u->ic->acc->prpl;
     1168                prpl = bu->ic->acc->prpl;
    11541169                if(strcmp(prpl->name, protocol) == 0
    1155                         && prpl->handle_cmp(u->handle, handle) == 0) {
    1156                         return u;
     1170                        && prpl->handle_cmp(bu->handle, handle) == 0) {
     1171                        return bu->ui_data;
    11571172                }
    11581173        }
     
    11791194        static char fallback[512];
    11801195       
    1181         user_t *u = peeruser(irc, handle, protocol);
     1196        irc_user_t *u = peeruser(irc, handle, protocol);
    11821197        if(u) {
    11831198                return u->nick;
     
    11881203}
    11891204
    1190 int otr_update_modeflags(irc_t *irc, user_t *u)
    1191 {
    1192         char *vb = set_getstr(&irc->set, "voice_buddies");
    1193         char *hb = set_getstr(&irc->set, "halfop_buddies");
    1194         char *ob = set_getstr(&irc->set, "op_buddies");
    1195         int encrypted = u->encrypted;
    1196         int trusted = u->encrypted > 1;
    1197         char flags[7];
    1198         int nflags=0;
    1199         char *p = flags;
    1200         char *from;
    1201         int i;
    1202        
    1203         if(!strcmp(vb, "encrypted")) {
    1204                 *(p++) = encrypted ? '+' : '-';
    1205                 *(p++) = 'v';
    1206                 nflags++;
    1207         } else if(!strcmp(vb, "trusted")) {
    1208                 *(p++) = trusted ? '+' : '-';
    1209                 *(p++) = 'v';
    1210                 nflags++;
    1211         }
    1212         if(!strcmp(hb, "encrypted")) {
    1213                 *(p++) = encrypted ? '+' : '-';
    1214                 *(p++) = 'h';
    1215                 nflags++;
    1216         } else if(!strcmp(hb, "trusted")) {
    1217                 *(p++) = trusted ? '+' : '-';
    1218                 *(p++) = 'h';
    1219                 nflags++;
    1220         }
    1221         if(!strcmp(ob, "encrypted")) {
    1222                 *(p++) = encrypted ? '+' : '-';
    1223                 *(p++) = 'o';
    1224                 nflags++;
    1225         } else if(!strcmp(ob, "trusted")) {
    1226                 *(p++) = trusted ? '+' : '-';
    1227                 *(p++) = 'o';
    1228                 nflags++;
    1229         }
    1230         *p = '\0';
    1231        
    1232         p = g_malloc(nflags * (strlen(u->nick)+1) + 1);
    1233         *p = '\0';
    1234         if(!p)
    1235                 return 0;
    1236         for(i=0; i<nflags; i++) {
    1237                 strcat(p, " ");
    1238                 strcat(p, u->nick);
    1239         }
    1240         if(set_getbool(&irc->set, "simulate_netsplit"))
    1241                 from = g_strdup(irc->myhost);
    1242         else
    1243                 from = g_strdup_printf("%s!%s@%s", irc->mynick, irc->mynick, irc->myhost);
    1244         irc_write(irc, ":%s MODE %s %s%s", from, irc->channel, flags, p);
    1245         g_free(from);
    1246         g_free(p);
    1247                
     1205int otr_update_modeflags(irc_t *irc, irc_user_t *u)
     1206{
    12481207        return 1;
    12491208}
     
    14501409        irc_usermsg(irc, "\x1f" "connection contexts:\x1f (bold=currently encrypted)");
    14511410        for(ctx=irc->otr->us->context_root; ctx; ctx=ctx->next) {\
    1452                 user_t *u;
     1411                irc_user_t *u;
    14531412                char *userstring;
    14541413               
     
    15761535                irc->otr->sent_protocol = NULL;
    15771536                irc->otr->todo = NULL;
    1578                 b_input_add(from[0], GAIM_INPUT_READ, keygen_finish_handler, irc);
     1537                b_input_add(from[0], B_EV_IO_READ, keygen_finish_handler, irc);
    15791538        }
    15801539       
     
    16411600        irc_usermsg(irc, "%s", msg);
    16421601        if(filename[0]) {
    1643                 char *kf = g_strdup_printf("%s%s.otr_keys", global.conf->configdir, irc->nick);
     1602                char *kf = g_strdup_printf("%s%s.otr_keys", global.conf->configdir, irc->user->nick);
    16441603                char *tmp = g_strdup_printf("%s.new", kf);
    16451604                copyfile(filename, tmp);
     
    17091668{
    17101669        account_t *acc = (account_t *)data;
    1711        
    1712         if(keygen_in_progress(acc->irc, acc->user, acc->prpl->name)) {
    1713                 irc_usermsg(acc->irc, "keygen for %s/%s already in progress",
     1670        irc_t *irc = acc->bee->ui_data;
     1671       
     1672        if(keygen_in_progress(irc, acc->user, acc->prpl->name)) {
     1673                irc_usermsg(irc, "keygen for %s/%s already in progress",
    17141674                        acc->user, acc->prpl->name);
    17151675        } else {
    1716                 irc_usermsg(acc->irc, "starting background keygen for %s/%s",
     1676                irc_usermsg(irc, "starting background keygen for %s/%s",
    17171677                        acc->user, acc->prpl->name);
    1718                 irc_usermsg(acc->irc, "you will be notified when it completes");
    1719                 otr_keygen(acc->irc, acc->user, acc->prpl->name);
     1678                irc_usermsg(irc, "you will be notified when it completes");
     1679                otr_keygen(irc, acc->user, acc->prpl->name);
    17201680        }
    17211681}
Note: See TracChangeset for help on using the changeset viewer.