- Timestamp:
- 2008-08-09T23:00:38Z (16 years ago)
- Branches:
- master
- Children:
- a830512
- Parents:
- 280e655
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
account.c
r280e655 r4230221 235 235 } 236 236 237 char *set_eval_account_reconnect_delay( set_t *set, char *value ) 237 struct account_reconnect_delay 238 238 { 239 239 int start; 240 240 char op; 241 241 int step; 242 243 if( sscanf( value, "%d%c%d", &start, &op, &step ) == 3 && 244 step > 0 && ( op == '+' || op == '*' ) ) 245 return value; 242 int max; 243 }; 244 245 int 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 285 char *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 292 int 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 } 246 309 else 247 return set_eval_int( set, value ); 248 } 249 250 int account_reconnect_delay( account_t *a ) 251 { 252 char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" ); 253 int start, step; 254 char op; 255 256 if( sscanf( setting, "%d%c%d", &start, &op, &step ) == 3 && step > 0 ) 257 { 258 if( a->auto_reconnect_delay == 0 ) 259 return a->auto_reconnect_delay = start; 260 else if( op == '+' ) 261 return a->auto_reconnect_delay += step; 262 else if( op == '*' ) 263 return a->auto_reconnect_delay *= step; 264 } 265 else if( sscanf( setting, "%d", &start ) == 1 ) 266 { 267 return a->auto_reconnect_delay = start; 268 } 269 270 return 0; 271 } 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.