[5ebff60] | 1 | /********************************************************************\ |
---|
[b7d3cc34] | 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[0e788f5] | 4 | * Copyright 2002-2013 Wilmer van der Gaast and others * |
---|
[b7d3cc34] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* Account management functions */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
[6f10697] | 22 | if not, write to the Free Software Foundation, Inc., 51 Franklin St., |
---|
| 23 | Fifth Floor, Boston, MA 02110-1301 USA |
---|
[b7d3cc34] | 24 | */ |
---|
| 25 | |
---|
| 26 | #define BITLBEE_CORE |
---|
| 27 | #include "bitlbee.h" |
---|
| 28 | #include "account.h" |
---|
| 29 | |
---|
[5ebff60] | 30 | static char *set_eval_nick_source(set_t *set, char *value); |
---|
[06b39f2] | 31 | |
---|
[5ebff60] | 32 | account_t *account_add(bee_t *bee, struct prpl *prpl, char *user, char *pass) |
---|
[b7d3cc34] | 33 | { |
---|
| 34 | account_t *a; |
---|
[5100caa] | 35 | set_t *s; |
---|
[5ebff60] | 36 | char tag[strlen(prpl->name) + 10]; |
---|
| 37 | |
---|
| 38 | if (bee->accounts) { |
---|
| 39 | for (a = bee->accounts; a->next; a = a->next) { |
---|
| 40 | ; |
---|
| 41 | } |
---|
| 42 | a = a->next = g_new0(account_t, 1); |
---|
| 43 | } else { |
---|
| 44 | bee->accounts = a = g_new0(account_t, 1); |
---|
[b7d3cc34] | 45 | } |
---|
[5ebff60] | 46 | |
---|
[7b23afd] | 47 | a->prpl = prpl; |
---|
[5ebff60] | 48 | a->user = g_strdup(user); |
---|
| 49 | a->pass = g_strdup(pass); |
---|
[2b14eef] | 50 | a->auto_connect = 1; |
---|
[81e04e1] | 51 | a->bee = bee; |
---|
[5ebff60] | 52 | |
---|
| 53 | s = set_add(&a->set, "auto_connect", "true", set_eval_account, a); |
---|
[bb5ce568] | 54 | s->flags |= SET_NOSAVE; |
---|
[5ebff60] | 55 | |
---|
| 56 | s = set_add(&a->set, "auto_reconnect", "true", set_eval_bool, a); |
---|
| 57 | |
---|
| 58 | s = set_add(&a->set, "nick_format", NULL, NULL, a); |
---|
[badd148] | 59 | s->flags |= SET_NULL_OK; |
---|
[5ebff60] | 60 | |
---|
| 61 | s = set_add(&a->set, "nick_source", "handle", set_eval_nick_source, a); |
---|
[bb5ce568] | 62 | s->flags |= SET_NOSAVE; /* Just for bw compatibility! */ |
---|
[5ebff60] | 63 | |
---|
| 64 | s = set_add(&a->set, "password", NULL, set_eval_account, a); |
---|
[3ac6d9f] | 65 | s->flags |= SET_NOSAVE | SET_NULL_OK | SET_PASSWORD | ACC_SET_LOCKABLE; |
---|
[5ebff60] | 66 | |
---|
| 67 | s = set_add(&a->set, "tag", NULL, set_eval_account, a); |
---|
[bb5ce568] | 68 | s->flags |= SET_NOSAVE; |
---|
[5ebff60] | 69 | |
---|
| 70 | s = set_add(&a->set, "username", NULL, set_eval_account, a); |
---|
[3ac6d9f] | 71 | s->flags |= SET_NOSAVE | ACC_SET_OFFLINE_ONLY | ACC_SET_LOCKABLE; |
---|
[5ebff60] | 72 | set_setstr(&a->set, "username", user); |
---|
| 73 | |
---|
[3b3c50d9] | 74 | /* Hardcode some more clever tag guesses. */ |
---|
[5ebff60] | 75 | strcpy(tag, prpl->name); |
---|
| 76 | if (strcmp(prpl->name, "oscar") == 0) { |
---|
| 77 | if (g_ascii_isdigit(a->user[0])) { |
---|
| 78 | strcpy(tag, "icq"); |
---|
| 79 | } else { |
---|
| 80 | strcpy(tag, "aim"); |
---|
| 81 | } |
---|
| 82 | } else if (strcmp(prpl->name, "jabber") == 0) { |
---|
| 83 | if (strstr(a->user, "@gmail.com") || |
---|
| 84 | strstr(a->user, "@googlemail.com")) { |
---|
| 85 | strcpy(tag, "gtalk"); |
---|
| 86 | } |
---|
[3b3c50d9] | 87 | } |
---|
[5ebff60] | 88 | |
---|
| 89 | if (account_by_tag(bee, tag)) { |
---|
| 90 | char *numpos = tag + strlen(tag); |
---|
[40e6dac] | 91 | int i; |
---|
| 92 | |
---|
[5ebff60] | 93 | for (i = 2; i < 10000; i++) { |
---|
| 94 | sprintf(numpos, "%d", i); |
---|
| 95 | if (!account_by_tag(bee, tag)) { |
---|
[40e6dac] | 96 | break; |
---|
[5ebff60] | 97 | } |
---|
[40e6dac] | 98 | } |
---|
| 99 | } |
---|
[5ebff60] | 100 | set_setstr(&a->set, "tag", tag); |
---|
| 101 | |
---|
| 102 | a->nicks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
---|
| 103 | |
---|
[96863f6] | 104 | /* This function adds some more settings (and might want to do more |
---|
| 105 | things that have to be done now, although I can't think of anything. */ |
---|
[5ebff60] | 106 | if (prpl->init) { |
---|
| 107 | prpl->init(a); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | s = set_add(&a->set, "away", NULL, set_eval_account, a); |
---|
[58adb7e] | 111 | s->flags |= SET_NULL_OK; |
---|
[5ebff60] | 112 | |
---|
| 113 | if (a->flags & ACC_FLAG_STATUS_MESSAGE) { |
---|
| 114 | s = set_add(&a->set, "status", NULL, set_eval_account, a); |
---|
[58adb7e] | 115 | s->flags |= SET_NULL_OK; |
---|
| 116 | } |
---|
[5ebff60] | 117 | |
---|
[58adb7e] | 118 | return a; |
---|
[b7d3cc34] | 119 | } |
---|
| 120 | |
---|
[5ebff60] | 121 | char *set_eval_account(set_t *set, char *value) |
---|
[5100caa] | 122 | { |
---|
| 123 | account_t *acc = set->data; |
---|
[5ebff60] | 124 | |
---|
[5100caa] | 125 | /* Double-check: We refuse to edit on-line accounts. */ |
---|
[5ebff60] | 126 | if (set->flags & ACC_SET_OFFLINE_ONLY && acc->ic) { |
---|
[7125cb3] | 127 | return SET_INVALID; |
---|
[5ebff60] | 128 | } |
---|
| 129 | |
---|
| 130 | if (strcmp(set->key, "server") == 0) { |
---|
| 131 | g_free(acc->server); |
---|
| 132 | if (value && *value) { |
---|
| 133 | acc->server = g_strdup(value); |
---|
[30ce1ce] | 134 | return value; |
---|
[5ebff60] | 135 | } else { |
---|
| 136 | acc->server = g_strdup(set->def); |
---|
| 137 | return g_strdup(set->def); |
---|
[30ce1ce] | 138 | } |
---|
[5ebff60] | 139 | } else if (strcmp(set->key, "username") == 0) { |
---|
| 140 | g_free(acc->user); |
---|
| 141 | acc->user = g_strdup(value); |
---|
[3b32017] | 142 | return value; |
---|
[5ebff60] | 143 | } else if (strcmp(set->key, "password") == 0) { |
---|
[35987a1] | 144 | /* set -del allows /oper to be used to change the password or, |
---|
| 145 | iff oauth is enabled, reset the oauth credential magic. |
---|
| 146 | */ |
---|
[5ebff60] | 147 | if (!value) { |
---|
| 148 | if (set_getbool(&(acc->set), "oauth")) { |
---|
[35987a1] | 149 | value = ""; |
---|
| 150 | } else { |
---|
| 151 | value = PASSWORD_PENDING; |
---|
[5ebff60] | 152 | ((irc_t *) acc->bee->ui_data)->status |= OPER_HACK_ACCOUNT_PASSWORD; |
---|
| 153 | irc_rootmsg((irc_t *) acc->bee->ui_data, "You may now use /OPER to set the password"); |
---|
[35987a1] | 154 | } |
---|
| 155 | } |
---|
[5ebff60] | 156 | |
---|
| 157 | g_free(acc->pass); |
---|
| 158 | acc->pass = g_strdup(value); |
---|
| 159 | return NULL; /* password shouldn't be visible in plaintext! */ |
---|
| 160 | } else if (strcmp(set->key, "tag") == 0) { |
---|
[40e6dac] | 161 | account_t *oa; |
---|
[5ebff60] | 162 | |
---|
[40e6dac] | 163 | /* Enforce uniqueness. */ |
---|
[5ebff60] | 164 | if ((oa = account_by_tag(acc->bee, value)) && oa != acc) { |
---|
[40e6dac] | 165 | return SET_INVALID; |
---|
[5ebff60] | 166 | } |
---|
| 167 | |
---|
| 168 | g_free(acc->tag); |
---|
| 169 | acc->tag = g_strdup(value); |
---|
[40e6dac] | 170 | return value; |
---|
[5ebff60] | 171 | } else if (strcmp(set->key, "auto_connect") == 0) { |
---|
| 172 | if (!is_bool(value)) { |
---|
[7125cb3] | 173 | return SET_INVALID; |
---|
[5ebff60] | 174 | } |
---|
| 175 | |
---|
| 176 | acc->auto_connect = bool2int(value); |
---|
[5100caa] | 177 | return value; |
---|
[5ebff60] | 178 | } else if (strcmp(set->key, "away") == 0 || |
---|
| 179 | strcmp(set->key, "status") == 0) { |
---|
| 180 | if (acc->ic && acc->ic->flags & OPT_LOGGED_IN) { |
---|
[58adb7e] | 181 | /* If we're currently on-line, set the var now already |
---|
| 182 | (bit of a hack) and send an update. */ |
---|
[5ebff60] | 183 | g_free(set->value); |
---|
| 184 | set->value = g_strdup(value); |
---|
| 185 | |
---|
| 186 | imc_away_send_update(acc->ic); |
---|
[58adb7e] | 187 | } |
---|
[5ebff60] | 188 | |
---|
[58adb7e] | 189 | return value; |
---|
| 190 | } |
---|
[5ebff60] | 191 | |
---|
[7125cb3] | 192 | return SET_INVALID; |
---|
[5100caa] | 193 | } |
---|
| 194 | |
---|
[06b39f2] | 195 | /* For bw compatibility, have this write-only setting. */ |
---|
[5ebff60] | 196 | static char *set_eval_nick_source(set_t *set, char *value) |
---|
[06b39f2] | 197 | { |
---|
| 198 | account_t *a = set->data; |
---|
[5ebff60] | 199 | |
---|
| 200 | if (strcmp(value, "full_name") == 0) { |
---|
| 201 | set_setstr(&a->set, "nick_format", "%full_name"); |
---|
| 202 | } else if (strcmp(value, "first_name") == 0) { |
---|
| 203 | set_setstr(&a->set, "nick_format", "%first_name"); |
---|
| 204 | } else { |
---|
| 205 | set_setstr(&a->set, "nick_format", "%-@nick"); |
---|
| 206 | } |
---|
| 207 | |
---|
[06b39f2] | 208 | return value; |
---|
| 209 | } |
---|
| 210 | |
---|
[5ebff60] | 211 | account_t *account_get(bee_t *bee, const char *id) |
---|
[b7d3cc34] | 212 | { |
---|
| 213 | account_t *a, *ret = NULL; |
---|
[85616c3] | 214 | char *handle, *s; |
---|
[b7d3cc34] | 215 | int nr; |
---|
[5ebff60] | 216 | |
---|
[40e6dac] | 217 | /* Tags get priority above anything else. */ |
---|
[5ebff60] | 218 | if ((a = account_by_tag(bee, id))) { |
---|
[40e6dac] | 219 | return a; |
---|
[5ebff60] | 220 | } |
---|
| 221 | |
---|
[85616c3] | 222 | /* This checks if the id string ends with (...) */ |
---|
[5ebff60] | 223 | if ((handle = strchr(id, '(')) && (s = strchr(handle, ')')) && s[1] == 0) { |
---|
[85616c3] | 224 | struct prpl *proto; |
---|
[5ebff60] | 225 | |
---|
[85616c3] | 226 | *s = *handle = 0; |
---|
[5ebff60] | 227 | handle++; |
---|
| 228 | |
---|
| 229 | if ((proto = find_protocol(id))) { |
---|
| 230 | for (a = bee->accounts; a; a = a->next) { |
---|
| 231 | if (a->prpl == proto && |
---|
| 232 | a->prpl->handle_cmp(handle, a->user) == 0) { |
---|
[85616c3] | 233 | ret = a; |
---|
[5ebff60] | 234 | } |
---|
| 235 | } |
---|
[85616c3] | 236 | } |
---|
[5ebff60] | 237 | |
---|
[85616c3] | 238 | /* Restore the string. */ |
---|
[5ebff60] | 239 | handle--; |
---|
[85616c3] | 240 | *handle = '('; |
---|
| 241 | *s = ')'; |
---|
[5ebff60] | 242 | |
---|
| 243 | if (ret) { |
---|
[85616c3] | 244 | return ret; |
---|
[5ebff60] | 245 | } |
---|
[85616c3] | 246 | } |
---|
[5ebff60] | 247 | |
---|
| 248 | if (sscanf(id, "%d", &nr) == 1 && nr < 1000) { |
---|
| 249 | for (a = bee->accounts; a; a = a->next) { |
---|
| 250 | if ((nr--) == 0) { |
---|
| 251 | return(a); |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | return(NULL); |
---|
[b7d3cc34] | 256 | } |
---|
[5ebff60] | 257 | |
---|
| 258 | for (a = bee->accounts; a; a = a->next) { |
---|
| 259 | if (g_strcasecmp(id, a->prpl->name) == 0) { |
---|
| 260 | if (!ret) { |
---|
[b7d3cc34] | 261 | ret = a; |
---|
[5ebff60] | 262 | } else { |
---|
| 263 | return(NULL); /* We don't want to match more than one... */ |
---|
| 264 | } |
---|
| 265 | } else if (strstr(a->user, id)) { |
---|
| 266 | if (!ret) { |
---|
[b7d3cc34] | 267 | ret = a; |
---|
[5ebff60] | 268 | } else { |
---|
| 269 | return(NULL); |
---|
| 270 | } |
---|
[b7d3cc34] | 271 | } |
---|
| 272 | } |
---|
[5ebff60] | 273 | |
---|
| 274 | return(ret); |
---|
[b7d3cc34] | 275 | } |
---|
| 276 | |
---|
[5ebff60] | 277 | account_t *account_by_tag(bee_t *bee, const char *tag) |
---|
[40e6dac] | 278 | { |
---|
| 279 | account_t *a; |
---|
[5ebff60] | 280 | |
---|
| 281 | for (a = bee->accounts; a; a = a->next) { |
---|
| 282 | if (a->tag && g_strcasecmp(tag, a->tag) == 0) { |
---|
[40e6dac] | 283 | return a; |
---|
[5ebff60] | 284 | } |
---|
| 285 | } |
---|
| 286 | |
---|
[40e6dac] | 287 | return NULL; |
---|
| 288 | } |
---|
| 289 | |
---|
[5ebff60] | 290 | void account_del(bee_t *bee, account_t *acc) |
---|
[b7d3cc34] | 291 | { |
---|
| 292 | account_t *a, *l = NULL; |
---|
[5ebff60] | 293 | |
---|
| 294 | if (acc->ic) { |
---|
[fa75134] | 295 | /* Caller should have checked, accounts still in use can't be deleted. */ |
---|
| 296 | return; |
---|
[5ebff60] | 297 | } |
---|
| 298 | |
---|
| 299 | for (a = bee->accounts; a; a = (l = a)->next) { |
---|
| 300 | if (a == acc) { |
---|
| 301 | if (l) { |
---|
[b7d3cc34] | 302 | l->next = a->next; |
---|
[5ebff60] | 303 | } else { |
---|
[81e04e1] | 304 | bee->accounts = a->next; |
---|
[5ebff60] | 305 | } |
---|
| 306 | |
---|
[81e04e1] | 307 | /** FIXME |
---|
| 308 | for( c = bee->chatrooms; c; c = nc ) |
---|
[f86a3d5] | 309 | { |
---|
[5ebff60] | 310 | nc = c->next; |
---|
| 311 | if( acc == c->acc ) |
---|
| 312 | chat_del( bee, c ); |
---|
[f86a3d5] | 313 | } |
---|
[81e04e1] | 314 | */ |
---|
[5ebff60] | 315 | |
---|
| 316 | while (a->set) { |
---|
| 317 | set_del(&a->set, a->set->key); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | g_hash_table_destroy(a->nicks); |
---|
| 321 | |
---|
| 322 | g_free(a->tag); |
---|
| 323 | g_free(a->user); |
---|
| 324 | g_free(a->pass); |
---|
| 325 | g_free(a->server); |
---|
| 326 | if (a->reconnect) { /* This prevents any reconnect still queued to happen */ |
---|
| 327 | cancel_auto_reconnect(a); |
---|
| 328 | } |
---|
| 329 | g_free(a); |
---|
| 330 | |
---|
[b7d3cc34] | 331 | break; |
---|
| 332 | } |
---|
[5ebff60] | 333 | } |
---|
[b7d3cc34] | 334 | } |
---|
| 335 | |
---|
[5ebff60] | 336 | static gboolean account_on_timeout(gpointer d, gint fd, b_input_condition cond); |
---|
[748bcdd] | 337 | |
---|
[5ebff60] | 338 | void account_on(bee_t *bee, account_t *a) |
---|
[b7d3cc34] | 339 | { |
---|
[5ebff60] | 340 | if (a->ic) { |
---|
[b7d3cc34] | 341 | /* Trying to enable an already-enabled account */ |
---|
| 342 | return; |
---|
| 343 | } |
---|
[5ebff60] | 344 | |
---|
| 345 | cancel_auto_reconnect(a); |
---|
| 346 | |
---|
[b7d3cc34] | 347 | a->reconnect = 0; |
---|
[5ebff60] | 348 | a->prpl->login(a); |
---|
| 349 | |
---|
| 350 | if (a->ic && !(a->ic->flags & (OPT_SLOW_LOGIN | OPT_LOGGED_IN))) { |
---|
| 351 | a->ic->keepalive = b_timeout_add(120000, account_on_timeout, a->ic); |
---|
| 352 | } |
---|
[b7d3cc34] | 353 | } |
---|
| 354 | |
---|
[5ebff60] | 355 | void account_off(bee_t *bee, account_t *a) |
---|
[b7d3cc34] | 356 | { |
---|
[5ebff60] | 357 | imc_logout(a->ic, FALSE); |
---|
[0da65d5] | 358 | a->ic = NULL; |
---|
[5ebff60] | 359 | if (a->reconnect) { |
---|
[b7d3cc34] | 360 | /* Shouldn't happen */ |
---|
[5ebff60] | 361 | cancel_auto_reconnect(a); |
---|
[b7d3cc34] | 362 | } |
---|
| 363 | } |
---|
[280e655] | 364 | |
---|
[5ebff60] | 365 | static gboolean account_on_timeout(gpointer d, gint fd, b_input_condition cond) |
---|
[748bcdd] | 366 | { |
---|
| 367 | struct im_connection *ic = d; |
---|
[5ebff60] | 368 | |
---|
| 369 | if (!(ic->flags & (OPT_SLOW_LOGIN | OPT_LOGGED_IN))) { |
---|
| 370 | imcb_error(ic, "Connection timeout"); |
---|
| 371 | imc_logout(ic, TRUE); |
---|
[4cb21b7] | 372 | } |
---|
[5ebff60] | 373 | |
---|
[748bcdd] | 374 | return FALSE; |
---|
| 375 | } |
---|
| 376 | |
---|
[5ebff60] | 377 | struct account_reconnect_delay { |
---|
[280e655] | 378 | int start; |
---|
| 379 | char op; |
---|
| 380 | int step; |
---|
[4230221] | 381 | int max; |
---|
| 382 | }; |
---|
| 383 | |
---|
[5ebff60] | 384 | int account_reconnect_delay_parse(char *value, struct account_reconnect_delay *p) |
---|
[4230221] | 385 | { |
---|
[5ebff60] | 386 | memset(p, 0, sizeof(*p)); |
---|
[4230221] | 387 | /* A whole day seems like a sane "maximum maximum". */ |
---|
| 388 | p->max = 86400; |
---|
[5ebff60] | 389 | |
---|
[58adb7e] | 390 | /* Format: /[0-9]+([*+][0-9]+(<[0-9+])?)?/ */ |
---|
[5ebff60] | 391 | while (*value && g_ascii_isdigit(*value)) { |
---|
[4230221] | 392 | p->start = p->start * 10 + *value++ - '0'; |
---|
[5ebff60] | 393 | } |
---|
| 394 | |
---|
[4230221] | 395 | /* Sure, call me evil for implementing my own fscanf here, but it's |
---|
[7125cb3] | 396 | dead simple and I immediately know where to continue parsing. */ |
---|
[5ebff60] | 397 | |
---|
| 398 | if (*value == 0) { |
---|
[4230221] | 399 | /* If the string ends now, the delay is constant. */ |
---|
| 400 | return 1; |
---|
[5ebff60] | 401 | } else if (*value != '+' && *value != '*') { |
---|
[4230221] | 402 | /* Otherwise allow either a + or a * */ |
---|
| 403 | return 0; |
---|
[5ebff60] | 404 | } |
---|
| 405 | |
---|
[4230221] | 406 | p->op = *value++; |
---|
[5ebff60] | 407 | |
---|
[4230221] | 408 | /* + or * the delay by this number every time. */ |
---|
[5ebff60] | 409 | while (*value && g_ascii_isdigit(*value)) { |
---|
[4230221] | 410 | p->step = p->step * 10 + *value++ - '0'; |
---|
[5ebff60] | 411 | } |
---|
| 412 | |
---|
| 413 | if (*value == 0) { |
---|
[4230221] | 414 | /* Use the default maximum (one day). */ |
---|
| 415 | return 1; |
---|
[5ebff60] | 416 | } else if (*value != '<') { |
---|
[4230221] | 417 | return 0; |
---|
[5ebff60] | 418 | } |
---|
| 419 | |
---|
[4230221] | 420 | p->max = 0; |
---|
[5ebff60] | 421 | value++; |
---|
| 422 | while (*value && g_ascii_isdigit(*value)) { |
---|
[4230221] | 423 | p->max = p->max * 10 + *value++ - '0'; |
---|
[5ebff60] | 424 | } |
---|
| 425 | |
---|
[4230221] | 426 | return p->max > 0; |
---|
| 427 | } |
---|
| 428 | |
---|
[5ebff60] | 429 | char *set_eval_account_reconnect_delay(set_t *set, char *value) |
---|
[4230221] | 430 | { |
---|
| 431 | struct account_reconnect_delay p; |
---|
[5ebff60] | 432 | |
---|
| 433 | return account_reconnect_delay_parse(value, &p) ? value : SET_INVALID; |
---|
[280e655] | 434 | } |
---|
| 435 | |
---|
[5ebff60] | 436 | int account_reconnect_delay(account_t *a) |
---|
[280e655] | 437 | { |
---|
[5ebff60] | 438 | char *setting = set_getstr(&a->bee->set, "auto_reconnect_delay"); |
---|
[4230221] | 439 | struct account_reconnect_delay p; |
---|
[5ebff60] | 440 | |
---|
| 441 | if (account_reconnect_delay_parse(setting, &p)) { |
---|
| 442 | if (a->auto_reconnect_delay == 0) { |
---|
[4230221] | 443 | a->auto_reconnect_delay = p.start; |
---|
[5ebff60] | 444 | } else if (p.op == '+') { |
---|
[4230221] | 445 | a->auto_reconnect_delay += p.step; |
---|
[5ebff60] | 446 | } else if (p.op == '*') { |
---|
[4230221] | 447 | a->auto_reconnect_delay *= p.step; |
---|
[5ebff60] | 448 | } |
---|
| 449 | |
---|
| 450 | if (a->auto_reconnect_delay > p.max) { |
---|
[4230221] | 451 | a->auto_reconnect_delay = p.max; |
---|
[5ebff60] | 452 | } |
---|
| 453 | } else { |
---|
[4230221] | 454 | a->auto_reconnect_delay = 0; |
---|
[280e655] | 455 | } |
---|
[5ebff60] | 456 | |
---|
[4230221] | 457 | return a->auto_reconnect_delay; |
---|
[280e655] | 458 | } |
---|