Changeset 87f525e for account.c


Ignore:
Timestamp:
2008-08-10T10:42:52Z (16 years ago)
Author:
ulim <a.sporto+bee@…>
Branches:
master
Children:
a2b99ec
Parents:
8661caa (diff), a830512 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged in upstream r416 which includes my msn_write_msg patch. w00t! ;)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • account.c

    r8661caa r87f525e  
    234234        }
    235235}
     236
     237struct account_reconnect_delay
     238{
     239        int start;
     240        char op;
     241        int step;
     242        int max;
     243};
     244
     245int account_reconnect_delay_parse( char *value, struct account_reconnect_delay *p )
     246{
     247        memset( p, 0, sizeof( *p ) );
     248        /* A whole day seems like a sane "maximum maximum". */
     249        p->max = 86400;
     250       
     251        /* Format: /[0-9]+([*+][0-9]+(<[0-9+]))/ */
     252        while( *value && isdigit( *value ) )
     253                p->start = p->start * 10 + *value++ - '0';
     254       
     255        /* Sure, call me evil for implementing my own fscanf here, but it's
     256           dead simple and I'm immediately at the next part to parse. */
     257       
     258        if( *value == 0 )
     259                /* If the string ends now, the delay is constant. */
     260                return 1;
     261        else if( *value != '+' && *value != '*' )
     262                /* Otherwise allow either a + or a * */
     263                return 0;
     264       
     265        p->op = *value++;
     266       
     267        /* + or * the delay by this number every time. */
     268        while( *value && isdigit( *value ) )
     269                p->step = p->step * 10 + *value++ - '0';
     270       
     271        if( *value == 0 )
     272                /* Use the default maximum (one day). */
     273                return 1;
     274        else if( *value != '<' )
     275                return 0;
     276       
     277        p->max = 0;
     278        value ++;
     279        while( *value && isdigit( *value ) )
     280                p->max = p->max * 10 + *value++ - '0';
     281       
     282        return p->max > 0;
     283}
     284
     285char *set_eval_account_reconnect_delay( set_t *set, char *value )
     286{
     287        struct account_reconnect_delay p;
     288       
     289        return account_reconnect_delay_parse( value, &p ) ? value : NULL;
     290}
     291
     292int account_reconnect_delay( account_t *a )
     293{
     294        char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" );
     295        struct account_reconnect_delay p;
     296       
     297        if( account_reconnect_delay_parse( setting, &p ) )
     298        {
     299                if( a->auto_reconnect_delay == 0 )
     300                        a->auto_reconnect_delay = p.start;
     301                else if( p.op == '+' )
     302                        a->auto_reconnect_delay += p.step;
     303                else if( p.op == '*' )
     304                        a->auto_reconnect_delay *= p.step;
     305               
     306                if( a->auto_reconnect_delay > p.max )
     307                        a->auto_reconnect_delay = p.max;
     308        }
     309        else
     310        {
     311                a->auto_reconnect_delay = 0;
     312        }
     313       
     314        return a->auto_reconnect_delay;
     315}
Note: See TracChangeset for help on using the changeset viewer.