Changeset 87f525e


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! ;)

Files:
9 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}
  • account.h

    r8661caa r87f525e  
    3535       
    3636        int auto_connect;
     37        int auto_reconnect_delay;
    3738        int reconnect;
    3839       
     
    5253
    5354char *set_eval_account( set_t *set, char *value );
     55char *set_eval_account_reconnect_delay( set_t *set, char *value );
     56int account_reconnect_delay( account_t *a );
    5457
    5558#define ACC_SET_NOSAVE          1
  • conf.c

    r8661caa r87f525e  
    7979        }
    8080       
    81         while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hu:" ) ) >= 0 )
     81        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 )
    8282        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
    8383        {
     
    146146                                "  -h  Show this help page.\n" );
    147147                        return NULL;
     148                }
     149                else if( opt == 'R' )
     150                {
     151                        /* Backward compatibility; older BitlBees passed this
     152                           info using a command-line flag. Allow people to
     153                           upgrade from such a version for now. */
     154                        setenv( "_BITLBEE_RESTART_STATE", optarg, 0 );
    148155                }
    149156                else if( opt == 'u' )
  • doc/user-guide/commands.xml

    r8661caa r87f525e  
    321321        </bitlbee-setting>
    322322
    323         <bitlbee-setting name="auto_reconnect_delay" type="integer" scope="global">
    324                 <default>300</default>
    325 
    326                 <description>
    327                         <para>
    328                                 Tell BitlBee after how many seconds it should attempt to bring an IM-connection back up after a crash. It's not a good idea to set this value very low, it will cause too much useless traffic when an IM-server is down for a few hours.
     323        <bitlbee-setting name="auto_reconnect_delay" type="string" scope="global">
     324                <default>5*3&lt;900</default>
     325
     326                <description>
     327                        <para>
     328                                Tell BitlBee after how many seconds it should attempt to bring a broken IM-connection back up.
     329                        </para>
     330
     331                        <para>
     332                                This can be one integer, for a constant delay. One can also set it to something like &quot;10*10&quot;, which means wait for ten seconds on the first reconnect, multiply it by ten on every failure. Once successfully connected, this delay is re-set to the initial value. With &lt; you can give a maximum delay.
    329333                        </para>
    330334
  • irc.c

    r8661caa r87f525e  
    140140        set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
    141141        set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
    142         set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_int, irc );
     142        set_add( &irc->set, "auto_reconnect_delay", "5*3<900", set_eval_account_reconnect_delay, irc );
    143143        set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
    144144        set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
  • protocols/msn/msn.c

    r8661caa r87f525e  
    113113{
    114114        struct msn_switchboard *sb;
    115         struct msn_data *md = ic->proto_data;
    116115       
    117116        if( ( sb = msn_sb_by_handle( ic, who ) ) )
     
    122121        {
    123122                struct msn_message *m;
    124                 char buf[1024];
    125123               
    126124                /* Create a message. We have to arrange a usable switchboard, and send the message later. */
     
    129127                m->text = g_strdup( message );
    130128               
    131                 /* FIXME: *CHECK* the reliability of using spare sb's! */
    132                 if( ( sb = msn_sb_spare( ic ) ) )
    133                 {
    134                         debug( "Trying to use a spare switchboard to message %s", who );
    135                        
    136                         sb->who = g_strdup( who );
    137                         g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
    138                         if( msn_sb_write( sb, buf, strlen( buf ) ) )
    139                         {
    140                                 /* He/She should join the switchboard soon, let's queue the message. */
    141                                 sb->msgq = g_slist_append( sb->msgq, m );
    142                                 return( 1 );
    143                         }
    144                 }
    145                
    146                 debug( "Creating a new switchboard to message %s", who );
    147                
    148                 /* If we reach this line, there was no spare switchboard, so let's make one. */
    149                 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
    150                 if( !msn_write( ic, buf, strlen( buf ) ) )
    151                 {
    152                         g_free( m->who );
    153                         g_free( m->text );
    154                         g_free( m );
    155                        
    156                         return( 0 );
    157                 }
    158                
    159                 /* And queue the message to md. We'll pick it up when the switchboard comes up. */
    160                 md->msgq = g_slist_append( md->msgq, m );
    161                
    162                 /* FIXME: If the switchboard creation fails, the message will not be sent. */
    163                
    164                 return( 1 );
     129                return msn_sb_write_msg( ic, m );
    165130        }
    166131       
     
    252217{
    253218        struct msn_switchboard *sb;
    254         struct msn_data *md = ic->proto_data;
    255         char buf[1024];
    256219       
    257220        if( ( sb = msn_sb_by_handle( ic, who ) ) )
     
    263226        {
    264227                struct msn_message *m;
    265                
    266                 if( ( sb = msn_sb_spare( ic ) ) )
    267                 {
    268                         debug( "Trying to reuse an existing switchboard as a groupchat with %s", who );
    269                         g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
    270                         if( msn_sb_write( sb, buf, strlen( buf ) ) )
    271                                 return msn_sb_to_chat( sb );
    272                 }
    273                
    274                 /* If the stuff above failed for some reason: */
    275                 debug( "Creating a new switchboard to groupchat with %s", who );
    276                
    277                 /* Request a new switchboard. */
    278                 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
    279                 if( !msn_write( ic, buf, strlen( buf ) ) )
    280                         return( 0 );
    281228               
    282229                /* Create a magic message. This is quite hackish, but who cares? :-P */
     
    285232                m->text = g_strdup( GROUPCHAT_SWITCHBOARD_MESSAGE );
    286233               
    287                 /* Queue the magic message and cross your fingers. */
    288                 md->msgq = g_slist_append( md->msgq, m );
    289                
    290                 /* FIXME: Can I try to return something here already? */
     234                msn_sb_write_msg( ic, m );
     235
    291236                return NULL;
    292237        }
  • protocols/msn/msn.h

    r8661caa r87f525e  
    2323  Suite 330, Boston, MA  02111-1307  USA
    2424*/
     25
     26#ifndef _MSN_H
     27#define _MSN_H
    2528
    2629/* Some hackish magicstrings to make special-purpose messages/switchboards.
     
    176179void msn_sb_destroy( struct msn_switchboard *sb );
    177180gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond );
     181int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m );
     182
     183#endif //_MSN_H
  • protocols/msn/sb.c

    r8661caa r87f525e  
    4444                return( 0 );
    4545        }
     46       
     47        return( 1 );
     48}
     49
     50int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m )
     51{
     52        struct msn_data *md = ic->proto_data;
     53        struct msn_switchboard *sb;
     54        char buf[1024];
     55
     56        /* FIXME: *CHECK* the reliability of using spare sb's! */
     57        if( ( sb = msn_sb_spare( ic ) ) )
     58        {
     59                debug( "Trying to use a spare switchboard to message %s", m->who );
     60               
     61                sb->who = g_strdup( m->who );
     62                g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who );
     63                if( msn_sb_write( sb, buf, strlen( buf ) ) )
     64                {
     65                        /* He/She should join the switchboard soon, let's queue the message. */
     66                        sb->msgq = g_slist_append( sb->msgq, m );
     67                        return( 1 );
     68                }
     69        }
     70       
     71        debug( "Creating a new switchboard to message %s", m->who );
     72       
     73        /* If we reach this line, there was no spare switchboard, so let's make one. */
     74        g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
     75        if( !msn_write( ic, buf, strlen( buf ) ) )
     76        {
     77                g_free( m->who );
     78                g_free( m->text );
     79                g_free( m );
     80               
     81                return( 0 );
     82        }
     83       
     84        /* And queue the message to md. We'll pick it up when the switchboard comes up. */
     85        md->msgq = g_slist_append( md->msgq, m );
     86       
     87        /* FIXME: If the switchboard creation fails, the message will not be sent. */
    4688       
    4789        return( 1 );
  • protocols/nogaim.c

    r8661caa r87f525e  
    267267           protocols. */
    268268        imc_set_away( ic, u->away );
     269       
     270        /* Apparently we're connected successfully, so reset the
     271           exponential backoff timer. */
     272        ic->acc->auto_reconnect_delay = 0;
    269273}
    270274
     
    290294        user_t *t, *u;
    291295        account_t *a;
     296        int delay;
    292297       
    293298        /* Nested calls might happen sometimes, this is probably the best
     
    329334        }
    330335        else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
    331                  set_getbool( &a->set, "auto_reconnect" ) )
    332         {
    333                 int delay = set_getint( &irc->set, "auto_reconnect_delay" );
    334                
     336                 set_getbool( &a->set, "auto_reconnect" ) &&
     337                 ( delay = account_reconnect_delay( a ) ) > 0 )
     338        {
    335339                imcb_log( ic, "Reconnecting in %d seconds..", delay );
    336340                a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a );
Note: See TracChangeset for help on using the changeset viewer.