Changeset 5a71d9c


Ignore:
Timestamp:
2008-02-09T17:58:13Z (16 years ago)
Author:
Sven Moritz Hallberg <sm@…>
Branches:
master
Children:
f55cfe9
Parents:
a13855a
Message:
  • add support for setting ops/voice according to OTR msgstate
  • add 'otr trust' user command
  • support non-otr messages during keygen
  • run otr messages through strip_html
  • interpret <b> and <i> tags in html messages
  • record max message size in prpl
  • add 'encrypted' flag to user_t
  • cosmetics
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    ra13855a r5a71d9c  
    102102
    103103        irc_connection_list = g_slist_append( irc_connection_list, irc );
    104        
    105         set_add( &irc->set, "away_devoice", "true",  set_eval_away_devoice, irc );
     104
    106105        set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
    107106        set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
     
    115114        set_add( &irc->set, "handle_unknown", "root", NULL, irc );
    116115        set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
    117         set_add( &irc->set, "ops", "both", set_eval_ops, irc );
     116        set_add( &irc->set, "op_buddies", "false", set_eval_op_buddies, irc );
     117        set_add( &irc->set, "op_root", "true", set_eval_op_root, irc );
     118        set_add( &irc->set, "op_user", "true", set_eval_op_user, irc );
    118119        set_add( &irc->set, "password", NULL, passchange, irc );
    119120        set_add( &irc->set, "private", "true", set_eval_bool, irc );
     
    124125        set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
    125126        set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
     127        set_add( &irc->set, "voice_buddies", "notaway",  set_eval_voice_buddies, irc );
    126128       
    127129        conf_loaddefaults( irc );
     
    643645        char namelist[385] = "";
    644646        struct groupchat *c = NULL;
    645         char *ops = set_getstr( &irc->set, "ops" );
     647        char *oo = set_getstr(&irc->set, "op_buddies");
     648        char *vo = set_getstr(&irc->set, "voice_buddies");
    646649       
    647650        /* RFCs say there is no error reply allowed on NAMES, so when the
     
    658661                        }
    659662                       
    660                         if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
     663                        if( u->ic && !u->away && !strcmp(vo, "notaway") )
    661664                                strcat( namelist, "+" );
    662                         else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
    663                                  ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) )
     665                        else if( ( strcmp( u->nick, irc->mynick ) == 0 && set_getbool(&irc->set, "op_root") ) ||
     666                                 ( strcmp( u->nick, irc->nick ) == 0 && set_getbool(&irc->set, "op_user") ) ||
     667                                 ( !u->away && !strcmp(oo, "notaway") ) ||
     668                                 ( u->encrypted>1 && !strcmp(oo, "trusted") ) ||
     669                                 ( u->encrypted && !strcmp(oo, "encrypted") ) )
    664670                                strcat( namelist, "@" );
    665671                       
     
    674680                /* root and the user aren't in the channel userlist but should
    675681                   show up in /NAMES, so list them first: */
    676                 sprintf( namelist, "%s%s %s%s ", strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->mynick,
    677                                                  strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->nick );
    678                
     682                sprintf( namelist, "%s%s %s%s ", set_getbool(&irc->set, "op_root") ? "@" : "", irc->mynick,
     683                                                 set_getbool(&irc->set, "op_user") ? "@" : "", irc->nick );
     684               
     685                /* TODO: Honor op/voice_buddies in chats?! */
    679686                for( l = c->in_room; l; l = l->next ) if( ( u = user_findhandle( c->ic, l->data ) ) )
    680687                {
  • irc.h

    ra13855a r5a71d9c  
    3030
    3131#define IRC_MAX_LINE 512
    32 #define IRC_MAX_ARGS 8
     32#define IRC_MAX_ARGS 16
    3333
    3434#define IRC_LOGIN_TIMEOUT 60
  • lib/misc.c

    ra13855a r5a71d9c  
    143143        char *s = out, *cs;
    144144        int i, matched;
     145        int taglen;
    145146       
    146147        memset( out, 0, strlen( in ) + 1 );
     
    159160                                in ++;
    160161                       
     162                        taglen = in-cs-1;   /* not <0 because the above loop runs at least once */
    161163                        if( *in )
    162164                        {
    163                                 if( g_strncasecmp( cs+1, "br", 2) == 0 )
     165                                if( g_strncasecmp( cs+1, "b", taglen) == 0 )
     166                                        *(s++) = '\x02';
     167                                else if( g_strncasecmp( cs+1, "/b", taglen) == 0 )
     168                                        *(s++) = '\x02';
     169                                else if( g_strncasecmp( cs+1, "i", taglen) == 0 )
     170                                        *(s++) = '\x1f';
     171                                else if( g_strncasecmp( cs+1, "/i", taglen) == 0 )
     172                                        *(s++) = '\x1f';
     173                                else if( g_strncasecmp( cs+1, "br", 2) == 0 )
    164174                                        *(s++) = '\n';
    165175                                in ++;
  • otr.c

    ra13855a r5a71d9c  
    3535void op_gone_secure(void *opdata, ConnContext *context);
    3636
    37 void op_gone_secure(void *opdata, ConnContext *context);
    38 
    3937void op_gone_insecure(void *opdata, ConnContext *context);
    4038
     
    5351void cmd_otr_abort(irc_t *irc, char **args); /* TODO: does this cmd even make sense? */
    5452void cmd_otr_request(irc_t *irc, char **args); /* TODO: do we even need this? */
    55 void cmd_otr_auth(irc_t *irc, char **args);
     53void cmd_otr_smp(irc_t *irc, char **args);
     54void cmd_otr_trust(irc_t *irc, char **args);
    5655/* TODO: void cmd_otr_affirm(irc_t *irc, char **args); */
    5756void cmd_otr_fprints(irc_t *irc, char **args);
     
    6261        { "abort",    1, &cmd_otr_abort,    0 },
    6362        { "request",  1, &cmd_otr_request,  0 },
    64         { "auth",     2, &cmd_otr_auth,     0 },
     63        { "smp",      2, &cmd_otr_smp,      0 },
     64        { "trust",    6, &cmd_otr_trust,    0 },
    6565        { "fprints",  0, &cmd_otr_fprints,  0 },
    6666        { "info",     1, &cmd_otr_info,     0 },
     
    9797        const char *protocol);
    9898
    99 /* determine the nick for a given handle/protocol pair */
     99/* determine the nick for a given handle/protocol pair
     100   returns "handle/protocol" if not found */
    100101const char *peernick(irc_t *irc, const char *handle, const char *protocol);
     102
     103/* determine the user_t for a given handle/protocol pair
     104   returns NULL if not found */
     105user_t *peeruser(irc_t *irc, const char *handle, const char *protocol);
    101106
    102107/* handle SMP TLVs from a received message */
    103108void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs);
     109
     110/* update op/voice flag of given user according to encryption state and settings
     111   returns 0 if neither op_buddies nor voice_buddies is set to "encrypted",
     112   i.e. msgstate should be announced seperately */
     113int otr_update_modeflags(irc_t *irc, user_t *u);
    104114
    105115/* show the list of fingerprints associated with a given context */
     
    239249       
    240250    if(!g_mutex_trylock(ic->irc->otr_mutex)) {
    241         /* TODO: queue msgs received during keygen for later */
    242                 irc_usermsg(ic->irc, "msg from %s during keygen - dropped",
     251        user_t *u = user_findhandle(ic, handle);
     252       
     253        /* fallback for non-otr clients */
     254        if(u && !u->encrypted) {
     255                return g_strdup(msg);
     256        }
     257       
     258        /* TODO: queue msgs received during keygen for later? */
     259                irc_usermsg(ic->irc, "otr msg from %s during keygen - dropped",
    243260                        peernick(ic->irc, handle, ic->acc->prpl->name));
    244261                return NULL;
     
    283300int otr_send_message(struct im_connection *ic, const char *handle, const char *msg, int flags)
    284301{       
    285     int st;
    286     char *otrmsg = NULL;
    287     ConnContext *ctx = NULL;
    288    
     302        int st;
     303        char *otrmsg = NULL;
     304        ConnContext *ctx = NULL;
     305       
    289306    if(!g_mutex_trylock(ic->irc->otr_mutex)) {
    290         irc_usermsg(ic->irc, "msg to %s during keygen - not sent",
    291                 peernick(ic->irc, handle, ic->acc->prpl->name));
    292         return 1;
     307                user_t *u = user_findhandle(ic, handle);
     308       
     309                /* Fallback for non-otr clients.
     310                   Yes, we must be very sure this doesn't send stuff in the clear where it
     311                   shouldn't... */
     312                if(u && !u->encrypted) {
     313                        return ic->acc->prpl->buddy_msg(ic, (char *)handle, (char *)msg, flags);
     314                }
     315               
     316                /* otherwise refuse to send */
     317                irc_usermsg(ic->irc, "otr msg to %s not sent during keygen",
     318                        peernick(ic->irc, handle, ic->acc->prpl->name));
     319                return 1;
    293320    }
    294321   
     
    414441
    415442int op_display_otr_message(void *opdata, const char *accountname,
    416         const char *protocol, const char *username, const char *msg)
     443        const char *protocol, const char *username, const char *message)
    417444{
    418445        struct im_connection *ic = check_imc(opdata, accountname, protocol);
    419 
    420         log_message(LOGLVL_DEBUG, "op_display_otr_message '%s' '%s' '%s' '%s'", accountname, protocol, username, msg);
    421 
    422         irc_usermsg(ic->irc, "%s", msg);
    423 
     446        char *msg = g_strdup(message);
     447
     448        log_message(LOGLVL_DEBUG, "op_display_otr_message '%s' '%s' '%s' '%s'", accountname, protocol, username, message);
     449
     450        strip_html(msg);
     451        irc_usermsg(ic->irc, "otr: %s", msg);
     452
     453        g_free(msg);
    424454        return 0;
    425455}
     
    452482        struct im_connection *ic =
    453483                check_imc(opdata, context->accountname, context->protocol);
     484        user_t *u;
    454485
    455486        log_message(LOGLVL_DEBUG, "op_gone_secure '%s' '%s' '%s'", context->accountname, context->protocol, context->username);
    456487
    457         irc_usermsg(ic->irc, "conversation with %s is now off the record",
    458                 peernick(ic->irc, context->username, context->protocol));
     488        u = peeruser(ic->irc, context->username, context->protocol);
     489        if(!u) {
     490                log_message(LOGLVL_ERROR,
     491                        "BUG: otr.c: op_gone_secure: user_t for %s/%s not found!",
     492                        context->username, context->protocol);
     493                return;
     494        }
     495        if(context->active_fingerprint->trust[0])
     496                u->encrypted = 2;
     497        else
     498                u->encrypted = 1;
     499        if(!otr_update_modeflags(ic->irc, u))
     500                irc_usermsg(ic->irc, "conversation with %s is now off the record", u->nick);
    459501}
    460502
     
    463505        struct im_connection *ic =
    464506                check_imc(opdata, context->accountname, context->protocol);
     507        user_t *u;
    465508
    466509        log_message(LOGLVL_DEBUG, "op_gone_insecure '%s' '%s' '%s'", context->accountname, context->protocol, context->username);
    467510
    468         irc_usermsg(ic->irc, "conversation with %s is now in the clear",
    469                 peernick(ic->irc, context->username, context->protocol));
     511        u = peeruser(ic->irc, context->username, context->protocol);
     512        if(!u) {
     513                log_message(LOGLVL_ERROR,
     514                        "BUG: otr.c: op_gone_insecure: user_t for %s/%s not found!",
     515                        context->username, context->protocol);
     516                return;
     517        }
     518        u->encrypted = 0;
     519        if(!otr_update_modeflags(ic->irc, u))
     520                irc_usermsg(ic->irc, "conversation with %s is now in the clear", u->nick);
    470521}
    471522
     
    474525        struct im_connection *ic =
    475526                check_imc(opdata, context->accountname, context->protocol);
     527        user_t *u;
    476528
    477529        log_message(LOGLVL_DEBUG, "op_still_secure '%s' '%s' '%s' is_reply=%d",
    478530                context->accountname, context->protocol, context->username, is_reply);
    479531
    480         irc_usermsg(ic->irc, "otr connection with %s has been refreshed",
    481                 peernick(ic->irc, context->username, context->protocol));
     532        u = peeruser(ic->irc, context->username, context->protocol);
     533        if(!u) {
     534                log_message(LOGLVL_ERROR,
     535                        "BUG: otr.c: op_still_secure: user_t for %s/%s not found!",
     536                        context->username, context->protocol);
     537                return;
     538        }
     539        if(context->active_fingerprint->trust[0])
     540                u->encrypted = 2;
     541        else
     542                u->encrypted = 1;
     543        if(!otr_update_modeflags(ic->irc, u))
     544                irc_usermsg(ic->irc, "otr connection with %s has been refreshed", u->nick);
    482545}
    483546
    484547void op_log_message(void *opdata, const char *message)
    485548{
    486         log_message(LOGLVL_INFO, "%s", message);
     549        char *msg = g_strdup(message);
     550       
     551        strip_html(msg);
     552        log_message(LOGLVL_INFO, "otr: %s", msg);
     553        g_free(msg);
    487554}
    488555
    489556int op_max_message_size(void *opdata, ConnContext *context)
    490557{
    491         /* TODO: make max_message_size a property of the prpl.
    492                  the values here are taken from the libotr UPGRADING file */
    493         if(!strcmp(context->protocol, "msn"))
    494                 return 1409;
    495         if(!strcmp(context->protocol, "yahoo"))
    496                 return 832;
    497         if(!strcmp(context->protocol, "oscar"))
    498                 return 2343;
     558        struct im_connection *ic =
     559                check_imc(opdata, context->accountname, context->protocol);
     560
     561        return ic->acc->prpl->mms;
    499562}
    500563
     
    542605}
    543606
    544 void cmd_otr_auth(irc_t *irc, char **args)
     607void cmd_otr_smp(irc_t *irc, char **args)
    545608{
    546609        user_t *u;
     
    589652}
    590653
     654int hexval(char a)
     655{
     656        int x=tolower(a);
     657       
     658        if(x>='a' && x<='f')
     659                x = x - 'a' + 10;
     660        else if(x>='0' && x<='9')
     661                x = x - '0';
     662        else
     663                return -1;
     664       
     665        return x;
     666}
     667
     668void cmd_otr_trust(irc_t *irc, char **args)
     669{
     670        user_t *u;
     671        ConnContext *ctx;
     672        unsigned char raw[20];
     673        Fingerprint *fp;
     674        int i,j;
     675       
     676        u = user_find(irc, args[1]);
     677        if(!u || !u->ic) {
     678                irc_usermsg(irc, "%s: unknown user", args[1]);
     679                return;
     680        }
     681       
     682        ctx = otrl_context_find(irc->otr_us, u->handle,
     683                u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
     684        if(!ctx) {
     685                irc_usermsg(irc, "%s: no otr context with user", args[1]);
     686                return;
     687        }
     688       
     689        /* convert given fingerprint to raw representation */
     690        for(i=0; i<5; i++) {
     691                for(j=0; j<4; j++) {
     692                        char *p = args[2+i]+(2*j);
     693                        char *q = p+1;
     694                        int x, y;
     695                       
     696                        if(!*p || !*q) {
     697                                irc_usermsg(irc, "failed: truncated fingerprint block %d", i+1);
     698                                return;
     699                        }
     700                       
     701                        x = hexval(*p);
     702                        y = hexval(*q);
     703                        if(x<0) {
     704                                irc_usermsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+1, i+1);
     705                                return;
     706                        }
     707                        if(y<0) {
     708                                irc_usermsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+2, i+1);
     709                                return;
     710                        }
     711
     712                        raw[i*4+j] = x*16 + y;
     713                }
     714        }
     715        fp = otrl_context_find_fingerprint(ctx, raw, 0, NULL);
     716        if(!fp) {
     717                irc_usermsg(irc, "failed: no such fingerprint for %s", args[1]);
     718        } else {
     719                char *trust = args[7] ? args[7] : "affirmed";
     720                otrl_context_set_trust(fp, trust);
     721                irc_usermsg(irc, "fingerprint match, trust set to \"%s\"", trust);
     722                if(u->encrypted)
     723                        u->encrypted = 2;
     724                otr_update_modeflags(irc, u);
     725        }
     726}
     727
    591728void cmd_otr_fprints(irc_t *irc, char **args)
    592729{
     
    649786                u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL);
    650787        if(!ctx) {
    651                 irc_usermsg(irc, "no otr info on %s", args[1]);
     788                irc_usermsg(irc, "no otr context with %s", args[1]);
    652789                return;
    653790        }
     
    672809        irc_usermsg(irc, "  otr offer status: %s", offer_status);
    673810        irc_usermsg(irc, "  connection state: %s", message_state);
    674         irc_usermsg(irc, "  protocol version: %d", ctx->protocol_version);
    675         fp = ctx->active_fingerprint;
    676         if(!fp) {
    677                 irc_usermsg(irc, "  active f'print:   none");
    678         } else {
    679                 otrl_privkey_hash_to_human(human, fp->fingerprint);
    680                 if(!fp->trust || fp->trust[0] == '\0') {
    681                         trust="untrusted";
     811       
     812        if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
     813                irc_usermsg(irc, "  protocol version: %d", ctx->protocol_version);
     814                fp = ctx->active_fingerprint;
     815                if(!fp) {
     816                        irc_usermsg(irc, "  active f'print:   none?");
    682817                } else {
    683                         trust=fp->trust;
    684                 }
    685                 irc_usermsg(irc, "  active f'print:   %s (%s)", human, trust);
     818                        otrl_privkey_hash_to_human(human, fp->fingerprint);
     819                        if(!fp->trust || fp->trust[0] == '\0') {
     820                                trust="untrusted";
     821                        } else {
     822                                trust=fp->trust;
     823                        }
     824                        irc_usermsg(irc, "  active f'print:   %s (%s)", human, trust);
     825                }
    686826        }
    687827}
     
    809949}
    810950
    811 const char *peernick(irc_t *irc, const char *handle, const char *protocol)
     951user_t *peeruser(irc_t *irc, const char *handle, const char *protocol)
    812952{
    813953        user_t *u;
    814         static char fallback[512];
    815        
    816         g_snprintf(fallback, 511, "%s/%s", handle, protocol);
     954       
    817955        for(u=irc->users; u; u=u->next) {
    818956                struct prpl *prpl;
     
    822960                if(strcmp(prpl->name, protocol) == 0
    823961                        && prpl->handle_cmp(u->handle, handle) == 0) {
    824                         return u->nick;
    825                 }
    826         }
    827        
    828         return fallback;
     962                        return u;
     963                }
     964        }
     965       
     966        return NULL;
     967}
     968
     969const char *peernick(irc_t *irc, const char *handle, const char *protocol)
     970{
     971        static char fallback[512];
     972       
     973        user_t *u = peeruser(irc, handle, protocol);
     974        if(u) {
     975                return u->nick;
     976        } else {
     977                g_snprintf(fallback, 511, "%s/%s", handle, protocol);
     978                return fallback;
     979        }
     980}
     981
     982int otr_update_modeflags(irc_t *irc, user_t *u)
     983{
     984        char *vo = set_getstr(&irc->set, "voice_buddies");
     985        char *oo = set_getstr(&irc->set, "op_buddies");
     986        char eflag=0, tflag=0;
     987        int e = u->encrypted;
     988        int t = (u->encrypted > 1);
     989       
     990        if(!strcmp(vo, "encrypted"))
     991                eflag='v';
     992        else if(!strcmp(oo, "encrypted"))
     993                eflag='o';
     994        if(!strcmp(vo, "trusted"))
     995                tflag='v';
     996        else if(!strcmp(oo, "trusted"))
     997                tflag='o';
     998       
     999        if(!eflag)
     1000                return 0;
     1001       
     1002        if(tflag) {
     1003                irc_write( irc, ":%s!%s@%s MODE %s %c%c%c%c %s %s", irc->mynick, irc->mynick, irc->myhost,
     1004                        irc->channel, e?'+':'-', eflag, t?'+':'-', tflag, u->nick, u->nick );
     1005        } else {
     1006                irc_write( irc, ":%s!%s@%s MODE %s %c%c %s", irc->mynick, irc->mynick, irc->myhost,
     1007                        irc->channel, e?'+':'-', eflag, u->nick );
     1008        }
     1009               
     1010        return 1;
    8291011}
    8301012
     
    9661148        account_t *acc = (account_t *)data;
    9671149       
    968         /* TODO: remember that we didn't want a key? */
    9691150        irc_usermsg(acc->irc, "proceeding without key, otr inoperable on %s/%s",
    9701151                acc->user, acc->prpl->name);
     1152        /* TODO:
     1153        irc_usermsg(acc->irc, "setting otr policy for %s/%s to \"never\"",
     1154                acc->user, acc->prpl->name);
     1155        set_setstr(acc->set, "otr_policy", "never");
     1156        */
    9711157}
    9721158
  • protocols/jabber/jabber.c

    ra13855a r5a71d9c  
    511511       
    512512        ret->name = "jabber";
     513    ret->mms = 0;                        /* no limit */
    513514        ret->login = jabber_login;
    514515        ret->init = jabber_init;
  • protocols/msn/msn.c

    ra13855a r5a71d9c  
    372372       
    373373        ret->name = "msn";
     374    ret->mms = 1409;         /* this guess taken from libotr UPGRADING file */
    374375        ret->login = msn_login;
    375376        ret->init = msn_init;
  • protocols/nogaim.c

    ra13855a r5a71d9c  
    603603       
    604604        /* LISPy... */
    605         if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) &&         /* Don't do a thing when user doesn't want it */
    606             ( u->online ) &&                                            /* Don't touch offline people */
    607             ( ( ( u->online != oo ) && !u->away ) ||                    /* Voice joining people */
    608               ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* (De)voice people changing state */
     605        if( ( u->online ) &&                                            /* Don't touch offline people */
     606            ( ( ( u->online != oo ) && !u->away ) ||                    /* Do joining people */
     607              ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* Do people changing state */
    609608        {
    610609                char *from;
     
    619618                                                            ic->irc->myhost );
    620619                }
    621                 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
    622                                                           u->away?'-':'+', u->nick );
     620                if(!strcmp(set_getstr(&ic->irc->set, "voice_buddies"), "notaway")) {
     621                        irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
     622                                                                 u->away?'-':'+', u->nick );
     623                }
     624                if(!strcmp(set_getstr(&ic->irc->set, "op_buddies"), "notaway")) {
     625                        irc_write( ic->irc, ":%s MODE %s %co %s", from, ic->irc->channel,
     626                                                                 u->away?'-':'+', u->nick );
     627                }
    623628                g_free( from );
    624629        }
  • protocols/nogaim.h

    ra13855a r5a71d9c  
    136136         * - The user sees this name ie. when imcb_log() is used. */
    137137        const char *name;
     138    /* Maximum Message Size of this protocol.
     139     * - Introduced for OTR, in order to fragment large protocol messages.
     140     * - 0 means "unlimited". */
     141    unsigned int mms;
    138142
    139143        /* Added this one to be able to add per-account settings, don't think
  • protocols/oscar/oscar.c

    ra13855a r5a71d9c  
    26032603        struct prpl *ret = g_new0(struct prpl, 1);
    26042604        ret->name = "oscar";
     2605    ret->mms = 2343;       /* this guess taken from libotr UPGRADING file */
    26052606        ret->away_states = oscar_away_states;
    26062607        ret->init = oscar_init;
  • protocols/yahoo/yahoo.c

    ra13855a r5a71d9c  
    354354        struct prpl *ret = g_new0(struct prpl, 1);
    355355        ret->name = "yahoo";
     356    ret->mms = 832;           /* this guess taken from libotr UPGRADING file */
    356357        ret->init = byahoo_init;
    357358       
  • set.c

    ra13855a r5a71d9c  
    209209}
    210210
    211 char *set_eval_ops( set_t *set, char *value )
     211char *set_eval_op_root( set_t *set, char *value )
    212212{
    213213        irc_t *irc = set->data;
    214        
    215         if( g_strcasecmp( value, "user" ) == 0 )
    216                 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
    217                                                               irc->channel, "+o-o", irc->nick, irc->mynick );
    218         else if( g_strcasecmp( value, "root" ) == 0 )
    219                 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
    220                                                               irc->channel, "-o+o", irc->nick, irc->mynick );
    221         else if( g_strcasecmp( value, "both" ) == 0 )
    222                 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
    223                                                               irc->channel, "+oo", irc->nick, irc->mynick );
    224         else if( g_strcasecmp( value, "none" ) == 0 )
    225                 irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
    226                                                               irc->channel, "-oo", irc->nick, irc->mynick );
     214        char *ret = set_eval_bool(set, value);
     215        int b = bool2int(ret);
     216       
     217        irc_write( irc, ":%s!%s@%s MODE %s %s %s", irc->mynick, irc->mynick, irc->myhost,
     218                                                   irc->channel, b?"+o":"-o", irc->mynick );
     219        return ret;
     220}
     221
     222char *set_eval_op_user( set_t *set, char *value )
     223{
     224        irc_t *irc = set->data;
     225        char *ret = set_eval_bool(set, value);
     226        int b = bool2int(ret);
     227       
     228        irc_write( irc, ":%s!%s@%s MODE %s %s %s", irc->mynick, irc->mynick, irc->myhost,
     229                                                   irc->channel, b?"+o":"-o", irc->nick );
     230        return ret;
     231}
     232
     233/* generalized version of set_eval_op/voice_buddies */
     234char *set_eval_mode_buddies( set_t *set, char *value, char modeflag )
     235{
     236        irc_t *irc = set->data;
     237        char op[64], deop[64];
     238        int nop=0, ndeop=0;
     239        user_t *u;
     240        int mode;
     241       
     242        if(!strcmp(value, "false"))
     243                mode=0;
     244        else if(!strcmp(value, "encrypted"))
     245                mode=1;
     246        else if(!strcmp(value, "trusted"))
     247                mode=2;
     248        else if(!strcmp(value, "notaway"))
     249                mode=3;
    227250        else
    228251                return NULL;
    229252       
     253        /* sorry for calling them op/deop - too lazy for search+replace :P */
     254        op[0]='\0';
     255        deop[0]='\0';
     256        for(u=irc->users; u; u=u->next) {
     257                /* we're only concerned with online buddies */
     258                if(!u->ic || !u->online)
     259                        continue;
     260
     261                /* just in case... */
     262                if(strlen(u->nick) >= 64)
     263                        continue;
     264               
     265                /* dump out ops/deops when the corresponding name list fills up */
     266                if(strlen(op)+strlen(u->nick)+2 > 64) {
     267                        char *flags = g_strnfill(nop, modeflag);
     268                        irc_write( irc, ":%s!%s@%s MODE %s +%s%s", irc->mynick, irc->mynick, irc->myhost,
     269                                                               irc->channel, flags, op );
     270                    op[0]='\0';
     271                    g_free(flags);
     272                }
     273                if(strlen(deop)+strlen(u->nick)+2 > 64) {
     274                        char *flags = g_strnfill(ndeop, modeflag);
     275                        irc_write( irc, ":%s!%s@%s MODE %s -%s%s", irc->mynick, irc->mynick, irc->myhost,
     276                                                               irc->channel, flags, deop );
     277                    deop[0]='\0';
     278                    g_free(flags);
     279                }
     280               
     281                switch(mode) {
     282                /* "false" */
     283                case 0:
     284                        g_strlcat(deop, " ", 64);
     285                        g_strlcat(deop, u->nick, 64);
     286                        ndeop++;
     287                        break;
     288                /* "encrypted" */
     289                case 1:
     290                        if(u->encrypted) {
     291                                g_strlcat(op, " ", 64);
     292                                g_strlcat(op, u->nick, 64);
     293                                nop++;
     294                        } else {
     295                                g_strlcat(deop, " ", 64);
     296                                g_strlcat(deop, u->nick, 64);
     297                                ndeop++;
     298                        }
     299                        break;
     300                /* "trusted" */
     301                case 2:
     302                        if(u->encrypted > 1) {
     303                                g_strlcat(op, " ", 64);
     304                                g_strlcat(op, u->nick, 64);
     305                                nop++;
     306                        } else {
     307                                g_strlcat(deop, " ", 64);
     308                                g_strlcat(deop, u->nick, 64);
     309                                ndeop++;
     310                        }
     311                        break;
     312                /* "notaway" */
     313                case 3:
     314                        if(u->away) {
     315                                g_strlcat(deop, " ", 64);
     316                                g_strlcat(deop, u->nick, 64);
     317                                ndeop++;
     318                        } else {
     319                                g_strlcat(op, " ", 64);
     320                                g_strlcat(op, u->nick, 64);
     321                                nop++;
     322                        }
     323                }
     324        }
     325        /* dump anything left in op/deop lists */
     326        if(*op) {
     327                char *flags = g_strnfill(nop, modeflag);
     328                irc_write( irc, ":%s!%s@%s MODE %s +%s%s", irc->mynick, irc->mynick, irc->myhost,
     329                                                               irc->channel, flags, op );
     330                g_free(flags);
     331        }
     332        if(*deop) {
     333                char *flags = g_strnfill(ndeop, modeflag);
     334                irc_write( irc, ":%s!%s@%s MODE %s -%s%s", irc->mynick, irc->mynick, irc->myhost,
     335                                                       irc->channel, flags, deop );
     336                g_free(flags);
     337        }
     338       
    230339        return value;
     340}
     341
     342char *set_eval_op_buddies( set_t *set, char *value )
     343{
     344        return set_eval_mode_buddies(set, value, 'o');
     345}
     346
     347char *set_eval_voice_buddies( set_t *set, char *value )
     348{
     349        return set_eval_mode_buddies(set, value, 'v');
    231350}
    232351
  • set.h

    ra13855a r5a71d9c  
    9696/* Some not very generic evaluators that really shouldn't be here... */
    9797char *set_eval_to_char( set_t *set, char *value );
    98 char *set_eval_ops( set_t *set, char *value );
     98char *set_eval_op_root( set_t *set, char *value );
     99char *set_eval_op_user( set_t *set, char *value );
     100char *set_eval_op_buddies( set_t *set, char *value );
     101char *set_eval_voice_buddies( set_t *set, char *value );
    99102char *set_eval_charset( set_t *set, char *value );
    100103
  • user.h

    ra13855a r5a71d9c  
    3737        char is_private;
    3838        char online;
     39        char encrypted;
    3940       
    4041        char *handle;
Note: See TracChangeset for help on using the changeset viewer.