Changes in account.c [fa75134:3b32017]
Legend:
- Unmodified
- Added
- Removed
-
account.c
rfa75134 r3b32017 79 79 return NULL; 80 80 81 if( strcmp( set->key, "username" ) == 0 ) 81 if( strcmp( set->key, "server" ) == 0 ) 82 { 83 g_free( acc->server ); 84 if( value && *value ) 85 { 86 acc->server = g_strdup( value ); 87 return value; 88 } 89 else 90 { 91 acc->server = NULL; 92 return g_strdup( set->def ); 93 } 94 } 95 else if( value == NULL ) 96 { 97 /* Noop, the other three can't be NULL. */ 98 } 99 else if( strcmp( set->key, "username" ) == 0 ) 82 100 { 83 101 g_free( acc->user ); … … 90 108 acc->pass = g_strdup( value ); 91 109 return NULL; /* password shouldn't be visible in plaintext! */ 92 }93 else if( strcmp( set->key, "server" ) == 0 )94 {95 g_free( acc->server );96 if( *value )97 {98 acc->server = g_strdup( value );99 return value;100 }101 else102 {103 acc->server = NULL;104 return g_strdup( set->def );105 }106 110 } 107 111 else if( strcmp( set->key, "auto_connect" ) == 0 ) … … 234 238 } 235 239 } 240 241 struct account_reconnect_delay 242 { 243 int start; 244 char op; 245 int step; 246 int max; 247 }; 248 249 int account_reconnect_delay_parse( char *value, struct account_reconnect_delay *p ) 250 { 251 memset( p, 0, sizeof( *p ) ); 252 /* A whole day seems like a sane "maximum maximum". */ 253 p->max = 86400; 254 255 /* Format: /[0-9]+([*+][0-9]+(<[0-9+]))/ */ 256 while( *value && isdigit( *value ) ) 257 p->start = p->start * 10 + *value++ - '0'; 258 259 /* Sure, call me evil for implementing my own fscanf here, but it's 260 dead simple and I'm immediately at the next part to parse. */ 261 262 if( *value == 0 ) 263 /* If the string ends now, the delay is constant. */ 264 return 1; 265 else if( *value != '+' && *value != '*' ) 266 /* Otherwise allow either a + or a * */ 267 return 0; 268 269 p->op = *value++; 270 271 /* + or * the delay by this number every time. */ 272 while( *value && isdigit( *value ) ) 273 p->step = p->step * 10 + *value++ - '0'; 274 275 if( *value == 0 ) 276 /* Use the default maximum (one day). */ 277 return 1; 278 else if( *value != '<' ) 279 return 0; 280 281 p->max = 0; 282 value ++; 283 while( *value && isdigit( *value ) ) 284 p->max = p->max * 10 + *value++ - '0'; 285 286 return p->max > 0; 287 } 288 289 char *set_eval_account_reconnect_delay( set_t *set, char *value ) 290 { 291 struct account_reconnect_delay p; 292 293 return account_reconnect_delay_parse( value, &p ) ? value : NULL; 294 } 295 296 int account_reconnect_delay( account_t *a ) 297 { 298 char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" ); 299 struct account_reconnect_delay p; 300 301 if( account_reconnect_delay_parse( setting, &p ) ) 302 { 303 if( a->auto_reconnect_delay == 0 ) 304 a->auto_reconnect_delay = p.start; 305 else if( p.op == '+' ) 306 a->auto_reconnect_delay += p.step; 307 else if( p.op == '*' ) 308 a->auto_reconnect_delay *= p.step; 309 310 if( a->auto_reconnect_delay > p.max ) 311 a->auto_reconnect_delay = p.max; 312 } 313 else 314 { 315 a->auto_reconnect_delay = 0; 316 } 317 318 return a->auto_reconnect_delay; 319 }
Note: See TracChangeset
for help on using the changeset viewer.