! \brief * Write-back timer */
| 312 | * Write-back timer |
| 313 | */ |
| 314 | static inline int wb_timer(urecord_t* _r,query_list_t **ins_list) |
| 315 | { |
| 316 | ucontact_t* ptr, *t; |
| 317 | cstate_t old_state; |
| 318 | int op,ins_done=0; |
| 319 | |
| 320 | ptr = _r->contacts; |
| 321 | |
| 322 | if (rr_persist == RRP_LOAD_FROM_SQL && persist_urecord_kv_store(_r) != 0) |
| 323 | LM_DBG("failed to persist latest urecord K/V storage\n"); |
| 324 | |
| 325 | while(ptr) { |
| 326 | if (!VALID_CONTACT(ptr, act_time)) { |
| 327 | /* for forcibly expired contacts, DELETE event is already run */ |
| 328 | if (!FORCE_EXPIRED_CONTACT(ptr) && exists_ulcb_type(UL_CONTACT_EXPIRE)) |
| 329 | run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL); |
| 330 | |
| 331 | LM_DBG("Binding '%.*s','%.*s' has expired\n", |
| 332 | ptr->aor->len, ZSW(ptr->aor->s), |
| 333 | ptr->c.len, ZSW(ptr->c.s)); |
| 334 | |
| 335 | if (have_mem_storage()) |
| 336 | update_stat( _r->slot->d->expires, 1); |
| 337 | |
| 338 | t = ptr; |
| 339 | ptr = ptr->next; |
| 340 | |
| 341 | /* Should we remove the contact from the database ? */ |
| 342 | if (cid_vals && st_expired_ucontact(t) == 1 |
| 343 | && !(t->flags & FL_MEM)) { |
| 344 | VAL_BIGINT(cid_vals+cid_len) = t->contact_id; |
| 345 | if ((++cid_len) == max_contact_delete) { |
| 346 | if (db_multiple_ucontact_delete(_r->domain, cid_keys, |
| 347 | cid_vals, cid_len) < 0) { |
| 348 | LM_ERR("failed to delete contacts from database\n"); |
| 349 | /* pass over these contacts; we will try to delete |
| 350 | * them later */ |
| 351 | cid_len = 0; |
| 352 | |
| 353 | /* do not delete from memory now - if we do, we'll get |
| 354 | * a stuck record in DB. Future registrations will not |
| 355 | * be able to get inserted due to index collision */ |
| 356 | continue; |
| 357 | } |
| 358 | cid_len = 0; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | mem_delete_ucontact(_r, t); |
| 363 | } else { |
| 364 | /* Determine the operation we have to do */ |
| 365 | old_state = ptr->state; |
| 366 | op = st_flush_ucontact(ptr); |
| 367 | |
| 368 | switch(op) { |
| 369 | case 0: /* do nothing, contact is synchronized */ |
| 370 | break; |
| 371 |
no test coverage detected