- Timestamp:
- 2009-03-12T19:10:06Z (15 years ago)
- Branches:
- master
- Children:
- 673a54c
- Parents:
- 9b55485
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
account.c
r9b55485 r823de9d 55 55 56 56 s = set_add( &a->set, "password", NULL, set_eval_account, a ); 57 s->flags |= ACC_SET_NOSAVE ;57 s->flags |= ACC_SET_NOSAVE | SET_NULL_OK; 58 58 59 59 s = set_add( &a->set, "username", NULL, set_eval_account, a ); … … 77 77 /* Double-check: We refuse to edit on-line accounts. */ 78 78 if( set->flags & ACC_SET_OFFLINE_ONLY && acc->ic ) 79 return NULL; 80 81 if( strcmp( set->key, "username" ) == 0 ) 79 return SET_INVALID; 80 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 = g_strdup( set->def ); 92 return g_strdup( set->def ); 93 } 94 } 95 else if( strcmp( set->key, "username" ) == 0 ) 82 96 { 83 97 g_free( acc->user ); … … 87 101 else if( strcmp( set->key, "password" ) == 0 ) 88 102 { 89 g_free( acc->pass ); 90 acc->pass = g_strdup( value ); 91 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; 103 if( value ) 104 { 105 g_free( acc->pass ); 106 acc->pass = g_strdup( value ); 107 return NULL; /* password shouldn't be visible in plaintext! */ 100 108 } 101 109 else 102 110 { 103 acc->server = NULL; 104 return g_strdup( set->def ); 111 /* NULL can (should) be stored in the set_t 112 variable, but is otherwise not correct. */ 113 return SET_INVALID; 105 114 } 106 115 } … … 108 117 { 109 118 if( !is_bool( value ) ) 110 return NULL;119 return SET_INVALID; 111 120 112 121 acc->auto_connect = bool2int( value ); … … 114 123 } 115 124 116 return NULL;125 return SET_INVALID; 117 126 } 118 127 … … 234 243 } 235 244 } 245 246 struct account_reconnect_delay 247 { 248 int start; 249 char op; 250 int step; 251 int max; 252 }; 253 254 int account_reconnect_delay_parse( char *value, struct account_reconnect_delay *p ) 255 { 256 memset( p, 0, sizeof( *p ) ); 257 /* A whole day seems like a sane "maximum maximum". */ 258 p->max = 86400; 259 260 /* Format: /[0-9]+([*+][0-9]+(<[0-9+]))/ */ 261 while( *value && isdigit( *value ) ) 262 p->start = p->start * 10 + *value++ - '0'; 263 264 /* Sure, call me evil for implementing my own fscanf here, but it's 265 dead simple and I immediately know where to continue parsing. */ 266 267 if( *value == 0 ) 268 /* If the string ends now, the delay is constant. */ 269 return 1; 270 else if( *value != '+' && *value != '*' ) 271 /* Otherwise allow either a + or a * */ 272 return 0; 273 274 p->op = *value++; 275 276 /* + or * the delay by this number every time. */ 277 while( *value && isdigit( *value ) ) 278 p->step = p->step * 10 + *value++ - '0'; 279 280 if( *value == 0 ) 281 /* Use the default maximum (one day). */ 282 return 1; 283 else if( *value != '<' ) 284 return 0; 285 286 p->max = 0; 287 value ++; 288 while( *value && isdigit( *value ) ) 289 p->max = p->max * 10 + *value++ - '0'; 290 291 return p->max > 0; 292 } 293 294 char *set_eval_account_reconnect_delay( set_t *set, char *value ) 295 { 296 struct account_reconnect_delay p; 297 298 return account_reconnect_delay_parse( value, &p ) ? value : SET_INVALID; 299 } 300 301 int account_reconnect_delay( account_t *a ) 302 { 303 char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" ); 304 struct account_reconnect_delay p; 305 306 if( account_reconnect_delay_parse( setting, &p ) ) 307 { 308 if( a->auto_reconnect_delay == 0 ) 309 a->auto_reconnect_delay = p.start; 310 else if( p.op == '+' ) 311 a->auto_reconnect_delay += p.step; 312 else if( p.op == '*' ) 313 a->auto_reconnect_delay *= p.step; 314 315 if( a->auto_reconnect_delay > p.max ) 316 a->auto_reconnect_delay = p.max; 317 } 318 else 319 { 320 a->auto_reconnect_delay = 0; 321 } 322 323 return a->auto_reconnect_delay; 324 }
Note: See TracChangeset
for help on using the changeset viewer.