Changeset c239fff


Ignore:
Timestamp:
2014-02-07T16:00:40Z (10 years ago)
Author:
unknown <pesco@…>
Branches:
master
Children:
e76cf26
Parents:
71004a3
Message:

close otr connections on quit, add 'otr disconnect *' command

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/user-guide/commands.xml

    r71004a3 rc239fff  
    413413                <bitlbee-command name="disconnect">
    414414                        <syntax>otr disconnect &lt;nick&gt;</syntax>
    415                        
    416                         <description>
    417                        
    418                                 <para>
    419                                         Resets the connection with the specified user to cleartext.
     415                        <syntax>otr disconnect *</syntax>
     416                       
     417                        <description>
     418                       
     419                                <para>
     420                                        Resets the connection with the specified user/all users to cleartext.
    420421                                </para>
    421422                               
  • otr.c

    r71004a3 rc239fff  
    208208int strsane(const char *s);
    209209
     210/* close the OTR connection with the given buddy */
     211gboolean otr_disconnect_user(irc_t *irc, irc_user_t *u);
     212
     213/* close all active OTR connections */
     214void otr_disconnect_all(irc_t *irc);
     215
    210216/* functions to be called for certain events */
    211217static const struct irc_plugin otr_plugin;
    212 
    213218
    214219/*** routines declared in otr.h: ***/
     
    283288{
    284289        otr_t *otr = irc->otr;
     290        otr_disconnect_all(irc);
    285291        b_event_remove(otr->timer);
    286292        otrl_userstate_free(otr->us);
     
    638644void op_gone_insecure(void *opdata, ConnContext *context)
    639645{
    640         /* XXX on 'otr disconnect', this gets called for every instance and we
    641          * get the message multiple times... */
    642 
    643646        struct im_connection *ic =
    644647                check_imc(opdata, context->accountname, context->protocol);
     
    949952        irc_user_t *u;
    950953
    951         u = irc_user_by_name(irc, args[1]);
    952         if(!u || !u->bu || !u->bu->ic) {
    953                 irc_rootmsg(irc, "%s: unknown user", args[1]);
    954                 return;
    955         }
    956        
    957         /* XXX we disconnect all instances; is that what we want? */
    958         otrl_message_disconnect_all_instances(irc->otr->us, &otr_ops,
    959                 u->bu->ic, u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, u->bu->handle);
    960        
    961         /* for some reason, libotr (4.0.0) doesn't do this itself: */
    962         if(!(u->flags & IRC_USER_OTR_ENCRYPTED))
    963                 return;
    964 
    965         ConnContext *ctx, *p;
    966         ctx = otrl_context_find(irc->otr->us, u->bu->handle, u->bu->ic->acc->user,
    967                 u->bu->ic->acc->prpl->name, OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL);
    968         if(!ctx) { /* huh? */
    969                 u->flags &= ( IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED );
    970                 return;
    971         }
    972 
    973         for(p=ctx; p && p->m_context == ctx->m_context; p=p->next)
    974                 op_gone_insecure(u->bu->ic, p);
     954        if(!strcmp("*", args[1])) {
     955                otr_disconnect_all(irc);
     956                irc_rootmsg(irc, "all conversations are now in cleartext");
     957        } else {
     958                u = irc_user_by_name(irc, args[1]);
     959                if(otr_disconnect_user(irc, u))
     960                        irc_usernotice(u, "conversation is now in cleartext");
     961                else
     962                        irc_rootmsg(irc, "%s: unknown user", args[1]);
     963        }
    975964}
    976965
     
    20061995}
    20071996
     1997/* close the OTR connection with the given buddy */
     1998gboolean otr_disconnect_user(irc_t *irc, irc_user_t *u)
     1999{
     2000        if(!u || !u->bu || !u->bu->ic)
     2001                return FALSE;
     2002
     2003        /* XXX we disconnect all instances; is that what we want? */
     2004        otrl_message_disconnect_all_instances(irc->otr->us, &otr_ops,
     2005                u->bu->ic, u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, u->bu->handle);
     2006       
     2007        u->flags &= ~IRC_USER_OTR_TRUSTED;
     2008        u->flags &= ~IRC_USER_OTR_ENCRYPTED;
     2009        otr_update_modeflags(irc, u);
     2010
     2011        return TRUE;
     2012}
     2013
     2014/* close all active OTR connections */
     2015void otr_disconnect_all(irc_t *irc)
     2016{
     2017        irc_user_t *u;
     2018        ConnContext *ctx;
     2019
     2020        for(ctx=irc->otr->us->context_root; ctx; ctx=ctx->next) {
     2021                if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
     2022                        u = peeruser(irc, ctx->username, ctx->protocol);
     2023                        (void) otr_disconnect_user(irc, u);
     2024                }
     2025        }
     2026}
     2027
    20082028/* vim: set noet ts=4 sw=4: */
Note: See TracChangeset for help on using the changeset viewer.