Changes in account.c [fa75134:286b28e]
Legend:
- Unmodified
- Added
- Removed
-
account.c
rfa75134 r286b28e 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 04Wilmer van der Gaast and others *4 * Copyright 2002-2010 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 27 27 #include "bitlbee.h" 28 28 #include "account.h" 29 #include "chat.h" 29 30 30 31 account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass ) … … 54 55 s = set_add( &a->set, "auto_reconnect", "true", set_eval_bool, a ); 55 56 57 s = set_add( &a->set, "nick_source", "handle", NULL, a ); 58 56 59 s = set_add( &a->set, "password", NULL, set_eval_account, a ); 57 s->flags |= ACC_SET_NOSAVE ;60 s->flags |= ACC_SET_NOSAVE | SET_NULL_OK; 58 61 59 62 s = set_add( &a->set, "username", NULL, set_eval_account, a ); … … 68 71 prpl->init( a ); 69 72 70 return( a ); 73 s = set_add( &a->set, "away", NULL, set_eval_account, a ); 74 s->flags |= SET_NULL_OK; 75 76 if( a->flags & ACC_FLAG_STATUS_MESSAGE ) 77 { 78 s = set_add( &a->set, "status", NULL, set_eval_account, a ); 79 s->flags |= SET_NULL_OK; 80 } 81 82 return a; 71 83 } 72 84 … … 77 89 /* Double-check: We refuse to edit on-line accounts. */ 78 90 if( set->flags & ACC_SET_OFFLINE_ONLY && acc->ic ) 79 return NULL; 80 81 if( strcmp( set->key, "username" ) == 0 ) 91 return SET_INVALID; 92 93 if( strcmp( set->key, "server" ) == 0 ) 94 { 95 g_free( acc->server ); 96 if( value && *value ) 97 { 98 acc->server = g_strdup( value ); 99 return value; 100 } 101 else 102 { 103 acc->server = g_strdup( set->def ); 104 return g_strdup( set->def ); 105 } 106 } 107 else if( strcmp( set->key, "username" ) == 0 ) 82 108 { 83 109 g_free( acc->user ); … … 87 113 else if( strcmp( set->key, "password" ) == 0 ) 88 114 { 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; 115 if( value ) 116 { 117 g_free( acc->pass ); 118 acc->pass = g_strdup( value ); 119 return NULL; /* password shouldn't be visible in plaintext! */ 100 120 } 101 121 else 102 122 { 103 acc->server = NULL; 104 return g_strdup( set->def ); 123 /* NULL can (should) be stored in the set_t 124 variable, but is otherwise not correct. */ 125 return SET_INVALID; 105 126 } 106 127 } … … 108 129 { 109 130 if( !is_bool( value ) ) 110 return NULL;131 return SET_INVALID; 111 132 112 133 acc->auto_connect = bool2int( value ); 113 134 return value; 114 135 } 115 116 return NULL; 136 else if( strcmp( set->key, "away" ) == 0 || 137 strcmp( set->key, "status" ) == 0 ) 138 { 139 if( acc->ic && acc->ic->flags & OPT_LOGGED_IN ) 140 { 141 /* If we're currently on-line, set the var now already 142 (bit of a hack) and send an update. */ 143 g_free( set->value ); 144 set->value = g_strdup( value ); 145 146 imc_away_send_update( acc->ic ); 147 } 148 149 return value; 150 } 151 152 return SET_INVALID; 117 153 } 118 154 … … 181 217 { 182 218 account_t *a, *l = NULL; 219 struct chat *c, *nc; 183 220 184 221 if( acc->ic ) … … 193 230 else 194 231 irc->accounts = a->next; 232 233 for( c = irc->chatrooms; c; c = nc ) 234 { 235 nc = c->next; 236 if( acc == c->acc ) 237 chat_del( irc, c ); 238 } 195 239 196 240 while( a->set ) … … 234 278 } 235 279 } 280 281 struct account_reconnect_delay 282 { 283 int start; 284 char op; 285 int step; 286 int max; 287 }; 288 289 int account_reconnect_delay_parse( char *value, struct account_reconnect_delay *p ) 290 { 291 memset( p, 0, sizeof( *p ) ); 292 /* A whole day seems like a sane "maximum maximum". */ 293 p->max = 86400; 294 295 /* Format: /[0-9]+([*+][0-9]+(<[0-9+])?)?/ */ 296 while( *value && isdigit( *value ) ) 297 p->start = p->start * 10 + *value++ - '0'; 298 299 /* Sure, call me evil for implementing my own fscanf here, but it's 300 dead simple and I immediately know where to continue parsing. */ 301 302 if( *value == 0 ) 303 /* If the string ends now, the delay is constant. */ 304 return 1; 305 else if( *value != '+' && *value != '*' ) 306 /* Otherwise allow either a + or a * */ 307 return 0; 308 309 p->op = *value++; 310 311 /* + or * the delay by this number every time. */ 312 while( *value && isdigit( *value ) ) 313 p->step = p->step * 10 + *value++ - '0'; 314 315 if( *value == 0 ) 316 /* Use the default maximum (one day). */ 317 return 1; 318 else if( *value != '<' ) 319 return 0; 320 321 p->max = 0; 322 value ++; 323 while( *value && isdigit( *value ) ) 324 p->max = p->max * 10 + *value++ - '0'; 325 326 return p->max > 0; 327 } 328 329 char *set_eval_account_reconnect_delay( set_t *set, char *value ) 330 { 331 struct account_reconnect_delay p; 332 333 return account_reconnect_delay_parse( value, &p ) ? value : SET_INVALID; 334 } 335 336 int account_reconnect_delay( account_t *a ) 337 { 338 char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" ); 339 struct account_reconnect_delay p; 340 341 if( account_reconnect_delay_parse( setting, &p ) ) 342 { 343 if( a->auto_reconnect_delay == 0 ) 344 a->auto_reconnect_delay = p.start; 345 else if( p.op == '+' ) 346 a->auto_reconnect_delay += p.step; 347 else if( p.op == '*' ) 348 a->auto_reconnect_delay *= p.step; 349 350 if( a->auto_reconnect_delay > p.max ) 351 a->auto_reconnect_delay = p.max; 352 } 353 else 354 { 355 a->auto_reconnect_delay = 0; 356 } 357 358 return a->auto_reconnect_delay; 359 }
Note: See TracChangeset
for help on using the changeset viewer.